Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming jquery(JS files) from a CDN (Google)

This one is a case of not doing your homework.:-)

Apart from dynamic loading advantage, does it make sense to include a JavaScript library(jQuery in my case ) from a Google server when I can load it from my server as a single file comprised of the 19kb jQuery zip file + the additional JavaScript code I have written – all compressed with a JS compressor and served HTTP deflated.

With Google server I’ll have 2(parallel) HTTP round trips. One to get the jquery file and the other to get the site JavaScript code. One 19kb and the other say 20-25kb. Under normal circumstances it would be a single 30-35kb download from my site.

like image 601
Cherian Avatar asked Nov 24 '08 04:11

Cherian


1 Answers

Consider that a jQuery script downloaded from the google CDN might well already be cached on a visitor's browser, since it has consistent headers and cache control no matter where it is downloaded from. Hence, on average most users will only have to download your site-specific javascript scripts. Also, CDN generally have faster response times than single servers, since they respond from a server nearest to your location.

There is no cut and dry answer to your question, as both approaches offer good performance on modern connections. You should profile your system under duress and see what solution offers the best results (and if such optimization is even needed).

like image 96
Eran Galperin Avatar answered Oct 21 '22 01:10

Eran Galperin