jQuery的CDN和远距过期标头 [英] jQuery's CDN and Far-Future Expire Headers

查看:86
本文介绍了jQuery的CDN和远距过期标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

为什么jQuery的CDN提供的内容缺乏远期的过期标头? (或者,我在这里做错了什么?")

背景

我正在Web项目上使用jQuery和jQuery Mobile.为了提供这些脚本,我使用jQuery的CDN,

感谢您的时间.

示例

jQuery CDN

http://code.jquery.com/jquery-1.6.4. min.js

响应:

HTTP/1.1 304 Not Modified
Date: Wed, 16 May 2012 00:05:27 GMT
ETag: "9e68e84-16615-6ad9bfc0+gzip"
Last-Modified: Mon, 12 Sep 2011 22:55:03 GMT
Server: ECS (dca/532A)
Vary: Accept-Encoding
X-Cache: HIT

Google CDN

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

响应:

HTTP/1.1 200 OK
age:134505
cache-control:public, max-age=31536000
content-encoding:gzip
content-length:32103
content-type:text/javascript; charset=UTF-8
date:Mon, 14 May 2012 10:45:15 GMT
expires:Tue, 14 May 2013 10:45:15 GMT
last-modified:Mon, 02 Apr 2012 18:24:28 GMT
server:sffe
status:200 OK
vary:Accept-Encoding
version:HTTP/1.1
x-content-type-options:nosniff
x-xss-protection:1; mode=block

请注意,expires:Tue, 14 May 2013 10:45:15 GMT

中的远期到期日期

解决方案

我正在使用Microsoft的CDN托管版本,该版本的有效期为1年:

http://ajax.aspnetcdn.com/ajax/jquery.mobile/1.1.0/jquery.mobile-1.1.0.min.js

CDN托管文件的完整列表.

@zuul在下面解释了为什么某些CDN托管项目的过期标头比其他标头更长的原因.谢谢!

解决方案

Microsoft还拥有一个CDN,用于托管jquery移动设备:

http://www.asp.net/ajaxLibrary/CDNjQueryMobile110.ashx

Expire-Date大约是未来一年!

Question

Why does content served from jQuery's CDN lack far-future expire headers? (or, "What am I doing wrong here?")

Background

I'm using jQuery and jQuery Mobile on a web project. To serve these scripts, I use jQuery's CDN, per their directions. However, I've noticed that these resources are served without far-future expires headers, which prevents browsers from being able to cache them intelligently.

Although the jQuery servers will respond with 304 Not Modified, that's not the same as an expire header the negates that request altogether. I realize the simple answer here is "because they don't" however, I'm wondering why they don't, and if there's some way I can serve this content, ideally from a CDN, with far-future expires headers.

Thanks for your time.

Examples

jQuery CDN

http://code.jquery.com/jquery-1.6.4.min.js

Response:

HTTP/1.1 304 Not Modified
Date: Wed, 16 May 2012 00:05:27 GMT
ETag: "9e68e84-16615-6ad9bfc0+gzip"
Last-Modified: Mon, 12 Sep 2011 22:55:03 GMT
Server: ECS (dca/532A)
Vary: Accept-Encoding
X-Cache: HIT

Google CDN

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

Response:

HTTP/1.1 200 OK
age:134505
cache-control:public, max-age=31536000
content-encoding:gzip
content-length:32103
content-type:text/javascript; charset=UTF-8
date:Mon, 14 May 2012 10:45:15 GMT
expires:Tue, 14 May 2013 10:45:15 GMT
last-modified:Mon, 02 Apr 2012 18:24:28 GMT
server:sffe
status:200 OK
vary:Accept-Encoding
version:HTTP/1.1
x-content-type-options:nosniff
x-xss-protection:1; mode=block

Note the far-future expires date in expires:Tue, 14 May 2013 10:45:15 GMT

Solution

I'm using Microsoft's CDN hosted version which features a 1 year expire date:

http://ajax.aspnetcdn.com/ajax/jquery.mobile/1.1.0/jquery.mobile-1.1.0.min.js

Full list of CDN hosted files.

@zuul explained below why some CDN hosted items have longer expire headers than others. Thanks!

解决方案

Microsoft also has a CDN wich is hosting the jquery mobile stuff:

http://www.asp.net/ajaxLibrary/CDNjQueryMobile110.ashx

Expire-Date is about 1 year in the future!

这篇关于jQuery的CDN和远距过期标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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