I have used Google Hosted Libraries for as long as I can remember, and it’s what we use on Category5.TV to accelerate the javascript end of our site. For all the javascript and CSS (plus images and so-on) we use that aren’t available through Google’s hosted solution, I use Amazon S3 and distribute it through Cloudflare to make it load quickly for our viewers.
I’ve been fast falling in love with Cloudflare’s CDNJS.
CDNJS boasts that it is in fact much faster than Google Hosted Libraries.
Neah… that can’t be true! Google’s the “big dog”… Cloudflare is still relatively new.
RELATED VIDEO
So I took a look. The first thing that shocked me was the absolute magnitude of how many javascript tools are available through CDNJS. Gone is the need to (for example) load jQuery from Google Hosted Libraries but then have to download and deploy a copy of Fancybox 2 locally or on your own CDN. CDNJS seems to have it all. Or at least a great selection, plus the ability to add a library yourself via GitHub.
Sorry, what? Yeah, baby.
So I thought, let’s run the world’s simplest test: how fast does wget receive the jQuery library on Linux? It may not be a realistic benchmark in all cases, but it gives us a bit of a look at how quickly each service delivers the js.
Here are those simple (but amazing) results from my location in Ontario, Canada:
Google Hosted Libaries
robbie@robbie-debian:/tmp$ wget http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
–2013-03-22 13:50:47– http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
Resolving ajax.googleapis.com… 74.125.133.95, 2607:f8b0:4001:c02::5f
Connecting to ajax.googleapis.com|74.125.133.95|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: unspecified [text/javascript]
Saving to: `jquery.min.js.1′ [ <=> ] 92,629 –.-K/s in 0.1s
2013-03-22 13:50:47 (798 KB/s) – `jquery.min.js.1′ saved [92629]
CDNJS
robbie@robbie-debian:/tmp$ wget http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js
–2013-03-22 13:49:57– http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js
Resolving cdnjs.cloudflare.com… 141.101.123.8, 190.93.243.8, 190.93.242.8, …
Connecting to cdnjs.cloudflare.com|141.101.123.8|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: unspecified [application/x-javascript]
Saving to: `jquery.min.js’ [ <=> ] 92,629 –.-K/s in 0.04s
2013-03-22 13:49:58 (2.21 MB/s) – `jquery.min.js’ saved [92629]
Note the filesize (92,629) is exactly the same; we’re dealing with the same version of jQuery here–identical files. Also note that I’ve used a non-secure (http) connection for each. The difference in speed is incredible.
Now, for a basic site, the fraction-of-a-second difference may not matter to you. But for a big site like mine, this kind of difference could mean a full second off the load time–possibly more! That’s unheard of for a simple copy-and-paste change in code.
Time to update Category5.TV. What about your site? Please comment below.
Update: Garbee made a great point in our IRC room: You’re only seeing results from my location. Fair enough. We want to make sure this isn’t just me that is experiencing such a massive difference. Therefore, please run this exact test yourself, and post your results below in a comment. I’m in Ontario, Canada. Where are you? Thanks!
First Day Results Extracted from Reader Comments:
- Me:
Ontario Canada – Google @ 798 KB/s, CDNJS @ 2.21 MB/s, CDNJS is 2.77x the speed of Google.
Brea California – Google @ 2.27 MB/s, CDNJS @ 14.5 MB/s, CDNJS is 6.39x the speed of Google. - Garbee:
Virginia USA – Google @ 429 KB/s, CDNJS @ 496 KB/s, CDNJS is 1.16x the speed of Google.
New Jersey USA – Google @ 104 KB/s, CDNJS @ 2.60 MB/s, CDNJS is 25x the speed of Google. - Chris Neves:
Montana USA – Google @ 123 KB/s, CDNJS @ 300 KB/s, CDNJS is 2.44x the speed of Google. - Alan Pope:
Farnborough UK – Google @ 1.26 MB/s, CDNJS @ 1.16 MB/s, Google is 1.08x the speed of CDNJS.
London England – Google @ 6.79 MB/s, CDNJS @ 4.72 MB/s, Google is 1.44x the speed of CDNJS. - steve5:
Leeds UK – Google @ 153 KB/s, CDNJS @ 178 KB/s, CDNJS is 1.16x the speed of Google. - Bryce:
Seattle Washington – Google @ 1.83 MB/s, CDNJS @ 659 KB/s, Google is 2.78x the speed of CDNJS. - Calvin:
Massachusetts USA
Test 1: Unsecure Connection – Google @ 810 KB/s, CDNJS @ 876 KB/s, CDNJS is 1.08x the speed of Google.
Test 2: Secure Connection – Google @ 721 KB/s, CDNJS @ 1.08 MB/s, CDNJS is 1.5x the speed of Google.