Coder Profile - Show off your skills, get a coder profile.
 
 
 
Speed Up Delivery of your JavaScript Libraries
Web Development
Hello,

I am going to show you how to speed up delivery of you external .js files along with examples. I will use the prototype and scriptaculous javascript libraries as a benchmark which contains 8 seperate .js files.

Unoptimized .JS

Here are the results using YSlow to benchmark the speed of the JS files downloading when there is no gzip compression, no cdn, and no minification of the js code:

Response Time (ms): 4477 (all files)
File Size (kb): 248.7

4.4 seconds to download some JS files! Thats 4.4 seconds, on broadband, to wait before the page even renders!!! So lets get that optimized.

Option 1 - Optimized .JS - Using Google

http://code.google.com/apis/ajaxlibs/documentation/index.html

This is a very quick and easy way to speed up the delivery of the library files to an acceptable level. The same files, gziped with cdn (not minimized, but gzip kind of makes up for that loss)... results in the following:

Response Time (ms): 1920 (all files)
File Size (kb): 61.2

Thats not bad at all, especially considering you get all the advantages that google offers (see the url above). It can be improved even more if your prepared to do some manual work (see option 2)

Option 2 - Optimized .JS - Doing it yourself

We can cut out all the extra response times by just merging the files in to a single js file. That would then take it down from about 4.5 seconds, down to about 1 second and there is no need to do an extra DNS lookup like you would with option 1 - oh look - you've beaten google already!

Minimize the source code using a tool such as jsminify (PHP), and then gzip it when sending it over to the visitor. Resulting in the file going from 248.7Kb to around about 60Kb, and the response time being even faster!

Conclusion

Never run a large library such as scriptaculous on a live website in the unoptimized form. Most people would be more than happy using Option 1 because its much more convenient and gives acceptable speeds, but Option 2 gives you the best speed gains and your not relying on googles website to always be fast (and online) to get the gains but you do have to do a lot more work to get everything going.

If you use a JS library such as jQuery then i would just go with Option 1. Not worth all the extra effort and the gains won't be so great for a small 20Kb library. But for large libraries, especially your own, go with option 2.

Kind regards,
Scott


Posted By VBAssassin
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
 
VBAssassin     Posted 1.73 Year Ago
 
 
"FireFox + FireFox (+ YSlow)" - i ment FireFox + FireBug + YSlow :-P my
bad.

Good job that info is in the comments now ;-)

Kind regards,
Scott
 
gunni     Posted 1.73 Year Ago
 
 
No, but I would not have known how to with firefox, too ;)
 
VBAssassin     Posted 1.73 Year Ago
 
 
Dunno how you would benchmark it on other configurations than FireFox + FireFox (+
YSlow)

Know of any others?

Kind regards,
Scott
 
gunni     Posted 1.73 Year Ago
 
 
It would be interesting to know with which browser/browsers you got those results -
and maybe posting results of other browsers. Maybe other browsers have been optimized
for such cases.
 
VBAssassin     Posted 1.77 Year Ago
 
 
Na, google use CDN's and if i'm affected thousands of others would be as
well. I also tried it from my own ISP and got the same kind of results.
 
Izzmo     Posted 1.77 Year Ago
 
 
Hmm, this can just be that your connection to Google's servers are faster than
CP's. Google has paid a lot of money to make sure it's server's are
fast and have very little traffic to each individual one, making processing time very
quick.
Page 1 of 1
More Articles By This Author
How to use Memcache on Windows
PHP Sessions = Member Database Cache
Speed Up Delivery of your JavaScript Libraries
AJAX - When to use it?
When to use OOP in PHP
Preventing raw PHP leaks on Apache
What makes a good PHP programmer?
Recently Posted "Web Development" Articles
Website Optimization
How to use Memcache on Windows
PHP Sessions = Member Database Cache
Speed Up Delivery of your JavaScript Libraries
A cool tool ^^
AJAX - When to use it?
Introduction To PHP
[PHP] XML
HTML vs XHTML
[PHP] XML: HTML DOM Basics
Recently Rated "Web Development" Articles
Embed flash into your website
PHP Sessions = Member Database Cache
What makes a good PHP programmer?
Website Optimization
Preventing raw PHP leaks on Apache
How to use Memcache on Windows
When to use OOP in PHP
AJAX - When to use it?
Speed Up Delivery of your JavaScript Libraries
[PHP] XML
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (2)
Hardware (1)
Internet & Web Sites (3)
Life In General (2)
Networking (1)
Operating Systems (5)
Other (2)
Programming (47)
Security (10)
Software Development (5)
Web Development (15)
search Search Inside
Web Development
 
 
Latest News About Coder Profile
Coder Profile Poll
Why do you get bored with programming?

Not enough time to do something productive
I run out of ideas
Too hard to show people my creations
Everything i do has too many errors, and it's too hard
I don't get bored!!!


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
1.28 Year Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2010, Scott Thompson, All Rights Reserved