Google CDN not gzipping jquery

后端 未结 2 1270
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 03:38

If I navigate here: http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js

I download 70k using Firefox 3.6.3 and I can confirm it is sending Accept-Encoding:

相关标签:
2条回答
  • I'm having it the other way around.

    The Google one is 24KB and the MS one is 70KB...

    0 讨论(0)
  • 2021-01-05 04:15

    About GZip support on Google's CDN:

    Google's CDN supports GZip compression. As far as I know it does not support Deflate, but that does not matter because all major browsers support both.

    You can verify this yourself using Rex Swain's very nice HTTP viewer; just enter "gzip" in the Accept-Encoding field.

    I have played around a little, and I think that Google's CDN requires browser whitelisting before sending compressed Javascript. If you sometimes see too fat responses from Google's CDN, then maybe this is what tripped you up. If you want to play with this, you can use Rex Swain's viewer again, and put a nonsense string in as User-Agent header.

    About the "automatic upgrade" URLs:

    IMHO it is not ideal to use the 1.x or 1.4.x links on Google's CDN (the ones without a fully qualified version number).

    The first reason is that Google is serving those URLs with a low Cache-Control max-age value of 1 hour. Google of course does this to facilitate quick updates when a new version of jQuery is released. (This may not be as bad for performance as it can initially seem. Google also sends revalidation and Last-Modified headers, so I assume Google's CDN fully supports revalidation.)

    The main reason why I don't like the automatic upgrade URLs is this: If you serve jQuery from one of the URLs with automatic upgrades, then you risk unknown incompatibility problems later on. A future version of jQuery could conflict with one of the likely many 3rd party scripts that you're using, and cause your pages to break silently.

    Conclusion:

    There are reasonable critiques against using Google's CDN. Some teams have a great build process with automatic script combining and minification, as well as a fast global CDN for their content. If you're on one of those teams, then maybe Google's CDN is not the best option for you. But form most 'common' sites, the best way to serve jQuery is to use Google's CDN with a full version identifier.

    0 讨论(0)
提交回复
热议问题