谷歌CDN不gzip压缩jQuery [英] Google CDN not gzipping jquery

查看:131
本文介绍了谷歌CDN不gzip压缩jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在这里浏览: http://ajax.googleapis .com/ajax/libs/jquery/1.4/jquery.min.js

我使用Firefox 3.6.3下载了70k,并且可以确认它正在发送Accept-Encoding:gzip.

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

如果我使用的是Microsoft: http://ajax .microsoft.com/ajax/jquery/jquery-1.4.2.min.js

If I use the Microsoft one: http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js

我下载了30k(它以Content-Encoding:gzip的形式出现)

I download 30k (and it comes through as Content-Encoding: gzip)

在常规网站(例如jquery.com)中使用jquery 1.4.2时,我也遇到了这种情况.足够有趣的是,通过gzip压缩了引用Google cdn上的jquery 1.3.2的堆栈溢出.

I am also experiencing this when using jquery 1.4.2 in regular sites eg jquery.com. Funily enough, stack overflow which references jquery 1.3.2 on the google cdn, is coming through gzipped.

为什么会这样?是Google的问题,还是我缺少了什么?

Why is this happening? Is it some kind of issue with google or am I missing something?

我住在澳大利亚墨尔本.

I live in Melbourne, Australia.

哎呀,混淆了链接. hmm http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js 对我有用.

oops mixed up the links. hmm http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js works for me.. looks like it is just the 1.4 inclusive one

推荐答案

关于Google CDN上的GZip支持:

Google的CDN支持GZip压缩.据我所知,它不支持Deflate,但这没关系,因为所有主流浏览器都支持Deflate.

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.

您可以使用雷克斯·斯温的非常漂亮的HTTP查看器进行验证.只需在接受编码"字段中输入"gzip"即可.

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

我玩了一些,我认为Google的CDN需要在发送压缩的Javascript之前将浏览器列入白名单.如果您有时会看到来自Google CDN的过分回应,那么也许这就是您的绊脚石.如果您想玩这个游戏,可以再次使用Rex Swain的查看器,并在其中添加一个废话字符串作为User-Agent标头.

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.

关于自动升级" URL:

恕我直言,使用Google CDN上的1.x或1.4.x链接(没有完全限定的版本号)不是理想的选择.

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).

第一个原因是Google提供的URL的Cache-Control max-age最大值不超过1小时.当然,Google这样做是为了在发布新版本的jQuery时促进快速更新. (这可能并不像最初看起来那样对性能造成不良影响.Google还会发送重新验证和Last-Modified标头,因此我认为Google的CDN完全支持重新验证.)

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.)

我不喜欢自动升级URL的主要原因是:如果您从其中一个提供自动升级的URL提供jQuery,则您以后可能会遇到未知的不兼容问题. jQuery的未来版本可能会与您正在使用的许多第三方脚本之一冲突,从而导致您的页面无提示中断.

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.

结论:

对使用Google的CDN的合理批评一个>.有些团队的构建过程非常出色,具有自动脚本合并和最小化功能,以及针对其内容的快速全局CDN.如果您属于其中一个团队,那么Google的CDN可能不是您的最佳选择.但是,在大多数常见"网站中,最好的jQuery服务方式是使用带有完整版本标识符的Google CDN .

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.

这篇关于谷歌CDN不gzip压缩jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆