CloudFlare

 

CDNJS: Community Moderated Javascript Libraries + CloudFlare

Cdnjs

If you're using a Javascript library, the ideal case is that your visitors arrive on your site with it already stored in their browser's cache. The more sites that use the same URL to reference the library, the more likely it is that it will be cached even for first-time visitors. Google realized the importance of this for some of the major Internet libraries when they created the Google Libraries API. Unfortunately, Google has limited the number of libraries to 11 and not given much guidance on the practice of updating existing libraries or adding new ones.

In early 2011, Ryan Kirkman and Thomas Davis recognized that there were a number of additional libraries that needed the benefit of a central repository any site could link to in order to get the shared caching benefit. They created CDNJS, a project that allowed anyone to add new javascript libraries that would then get moderated by the project's community. They needed to make the libraries globally accessible on a fast network, so they looked to popular CDNs. They originally chose Amazon's CloudFront service, but as CDNJS gained in popularity the price became prohibitive for the non-profit project. Amazon's service also didn't offer an easy way to implement SSL/HTTPS connections, which limited CDNJS to only those sites that weren't using encryption. Not ideal on either front.

A couple months ago I saw a Tweet from Paul Irish, one of the creators of jQuery who is on Google's Chrome dev team, who was talking about how CDNJS needed to find a long term solution to ensuring a fast, reliable, affordable network. I reached out to Paul and Ryan via Twitter and put them in touch with Chris Joel from our team. Immediately the benefits were obvious: CloudFlare could offer CDNJS a globally-distributed network with extremely low latency that could support SSL/HTTPS. In doing so, CloudFlare could further our mission of making the web a faster, more secure place.

Yesterday the system went live and all the CDNJS libraries are now powered by CloudFlare. You can use CDNJS without signing up for CloudFlare for your own site. Existing CDNJS URLs will continue to work but should be updated to the latest URLs for full SSL support. CDNJS's community retains full control over what libraries are included. As they moderate in new libraries, or updates to existing libraries, they will be automatically included on our network and available worldwide at lightening speeds. We've ensured that all the HTTP headers are set in order for visitors' browsers to cache the libraries for as long as possible. As a result, the more people who use CDNJS as the central repo for their javascript libraries, the more everyone using it will benefit.

Our network rocks for this application. In the comparisons we ran with the old setup versus the CloudFlare new setup, our latency times were about 1/3rd of what CDNJS was previously seeing. We even compare extremely well versus the Google Libraries API. Don't take our word for it, try it yourself! Run the following commands from your terminal window:

  • ping ajax.googleapis.com
  • ping cdnjs.cloudflare.com

Your results may vary, but here's what I'm seeing from a major DSL provider's network in San Francisco:

  • Google Libraries API Average Latency: 82ms
  • CloudFlare-Powered CDNJS Average Latency: 14ms

At CloudFlare, we believe that open source, community-driven projects like CDNJS are the tools upon which the future of the Internet will be built. CloudFlare is proud to provide the global CDN infrastructure that helps power that future.

Posted by Matthew Prince
Views | Favorited 0 Times

Comments (16)

Jun 16, 2011
legacy said...
I pinged both and CloudFlare averaged 141ms and Google averaged 708ms, big difference eh?
Jun 16, 2011
thumper said...
I pinged Google first and got 28ms, which I thought you couldn't beat... but, sure enough, CloudFlare pings at 1.6ms!!
Jun 16, 2011
Matthew Prince said...
:-)
Jun 17, 2011
manolo said...
pinging from Madrid (Spain) I get 34ms for cdjs.cloudflare.com and 27ms for ajax.googleapis.com
I tested it from two differente connections and obtained the same results in both cases.
Jun 17, 2011
Justin Paine said...
I'm seeing Google average 30ms and CloudFlare averaging 19ms here in NYC. :)
Jun 17, 2011
Albert said...
I get 21ms for Google and 45ms for Cloudflare on average from Vancouver, BC. I guess Cloudflare doesn't have edge nodes everywhere :(
Jun 17, 2011
Matthew Prince said...
Not yet.
Jun 19, 2011
Tim Lester said...
From Australia -
ping ajax.googleapis.com avg 181ms
ping cdnjs.cloudflare.com avg 173ms

We are in the sticks :)

Still better with CloudFlare and will only get better.

Jun 21, 2011
Duffy Brook said...
Averaging 90ms with Google and 76ms with Cloudflare out here in the middle of nowhere USA... Durango, CO.

Good job CF. I look forward to plugging these into my sites.

Jun 23, 2011
Steve Lawrence said...
ping cdnjs.cloudflare.com 55ms
ping cdnjs.cloudflare.com.cdn.cloudflare.net 39ms
I am from Calgary, AB (EH!)
Jun 23, 2011
Steve Lawrence said...
Woops. I copied the wrong line: ping googleapis.l.google.com 55ms. Doh.
Jun 26, 2011
univ said...
ping ajax.googleapis.com avg 58ms
ping cdnjs.cloudflare.com avg 56ms
Hof, Germany
Jun 29, 2011
Richard said...
Thanks for supporting a cool project like this. I'm definitely going to look at using them in the future. And to add to the references

Comcast in Valparaiso, IN
ajax.googleapis.com - 24ms
cdnjs.cloudflare.com - 12ms

But here's the cool one
My slicehost server in DFW
ajax.googleapis.com - 21ms
cdnjs.cloudflare.com - 0ms!!!! I assume they are pretty much in the same building :)

Jul 01, 2011
manolo said...
Manolo from Madrid (Spain) about 1 week later:
53 ms for ajax.googleapis.com
52 ms for cdnjs.cloudflare.com

I got better results the first time I tested it.

Aug 10, 2011
Nick Markwell said...
ajax.googleapis.com: 23.8ms
cdnjs.cloudflare.com: 11.1ms

not bad, not at all!

Apr 09, 2012
Joe said...
Now if only someone would port this functionality to Wordpress to assist or replace the Use Google Libraries plugin.

Leave a comment...