Google Page Speed message: https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js (1 hour)

cachecdniis-7jquerypage-speed

Google Page Speed is telling me to leverage browser caching for only this object:

https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js (1 hour)

As this is being delivered from an external server, I guess I can't tell browsers to cache it when they visit my site? I am using IIS7 and have already implemented caching for 7 days (as per the config listed here https://stackoverflow.com/questions/642954/iis7-cache-control),

Therefore, should I copy the file to my web server and then reference and cache it on there?

Best Answer

Change the URL in your HTML from

https://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js

to

//ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js

Explanation:

  • The opening // instead of https:// is a shorthand -- supported by all major browsers -- which means "the same protocol as the parent page is using". In other words, if your own site uses SSL, then jQuery will be served over SSL. If not, then your users will use plain HTTP for jQuery, and benefit from the faster connection setup un-encrypted HTTP has.

  • When serving content with a full version number -- the 1.6.0 part -- Google's CDN will automatically use long caching headers. The URL you used means "the newest in the 1.6 series", and is served with shorter caching headers, so that Google can quickly update when jQuery releases a new version.

You can verify that this works with Rex Swain's HTTP Viewer if you'd like. (NB: this HTTP viewer doesn't support the // shorthand, but browsers do.)