Subscribe to receive notifications of new posts:

CDNJS: Community Moderated Javascript Libraries + CloudFlare

06/16/2011

3 min read

CDNJS: Community Moderated Javascript Libraries + CloudFlare

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.

We protect entire corporate networks, help customers build Internet-scale applications efficiently, accelerate any website or Internet application, ward off DDoS attacks, keep hackers at bay, and can help you on your journey to Zero Trust.

Visit 1.1.1.1 from any device to get started with our free app that makes your Internet faster and safer.

To learn more about our mission to help build a better Internet, start here. If you're looking for a new career direction, check out our open positions.
JavaScriptCommunityCDNJS

Follow on X

Matthew Prince|@eastdakota
Cloudflare|@cloudflare

Related posts