Over a million developers have joined DZone.

Let a big company host your JavaScript libraries

· Web Dev Zone
Big companies often use Content Delivery Networks (CDNs). Such a network consists of servers spread all over the world that all host the same content which ensures fast delivery. Some CDNs also host popular JavaScript libraries for the public, for free. Dave Ward gives three reasons why you might want to use such hosted libraries instead of storing them next to your own code:

  • Decreased latency: Chances are high that a CDN server is closer to a user than your own server. Thus: faster delivery.
  • Increased parallelism: Some browsers impose per-host limits on the number of connections. If your JavaScript libraries come from a different server, more of your own content can be loaded in parallel.
  • Better caching: If several sites use the same CDN, a copy of your library might already be cached in a user’s browser.

Comments:

  • Naturally, a reason against it is that it does not always work when you work offline, with file URLs. If that matters, you can dynamically load your libraries and switch to locally stored versions if the URL protocol is file.
  • The post suggests to use protocol-relative URLs if you want you site to work both with HTTP and HTTPS. This breaks down if you are using file URLs to test your site (as the CDNs cannot be reached via that protocol).

Here are links to what is available:

  • Google (most major JavaScript libraries)
  • Microsoft hosts several jQuery files, including jQuery Templates.
    • Note: ajax.microsoft.com was renamed to ajax.aspnetcdn.com. Isn’t the latter more ugly? Or was the intention to subtly market ASP.NET?
Topics:

Published at DZone with permission of Axel Rauschmayer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}