Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it faster to bundle jquery w/ one's scripts or to use a public cdn?

I'm hosting the javascript for my site on Cloudfront. Should I bundle jQuery in with the package, or use a public CDN? I'm primarily interested in mobile performance.

The pro of bundling is one fewer script file to download. The pro of a public CDN is that it's more likely to already be in the user's cache.

It sounds like the CDN to pick for likelihood to have in cache is Google's (based on the research here: http://royal.pingdom.com/2012/06/20/jquery-numbers/), but in practice does that outweigh having one fewer file? When you take into account the % of sites that use jQuery (~50%) * the percentage of those that use Google's CDN (25%) * the percentage of those using jQuery 1.10.2 (??%), is a significant chunk of my visitors going to have it cached?

like image 837
josh Avatar asked Dec 05 '25 10:12

josh


1 Answers

Bundling is not a recommended option as set out in this blog post by the Google Chrome V8 developers.

The recommended solution is to use open-source libraries from public CDN and serve the other files separately.

Since you are concerned about the mobile performance, I would recommend you to:

  1. Use opensource CDN for opensource resources.
  2. Use better compression as mobile networks are usually bandwidth constrained. Small file sizes translate to faster downloads.
  3. Use HTTP/2 Multiplexing effectively.
  4. Use HTTP/2 Server Push if possible.

PageCDN does all of this for you. It can mutiplex public libraries and private files over the single connection. Plus, it compresses resources using brotli-11 compression that compresses files far more tightly. It also supports immutable caching and HTTP/2 Server Push.

like image 135
Hamid Sarfraz Avatar answered Dec 07 '25 11:12

Hamid Sarfraz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!