有没有最新jquery的cdn,有缓存时间吗?

发布于 2024-11-07 10:00:26 字数 315 浏览 2 评论 0原文

jquery 使您可以执行以下操作:

 <script src="http://code.jquery.com/jquery-latest.js"></script>

问题是文件没有任何到期日期,因此客户端始终需要它。

另一个选项是 http://ajax.googleapis.com/ajax/libs/jquery/xxx/jquery.min.js ,它的有效期为 1 年

因此,有人知道提供 jquery-latest 的 CDN .js 有一些缓存时间?

jquery gives you the possibility to do a:

 <script src="http://code.jquery.com/jquery-latest.js"></script>

the problem is that file hasn't any expiration date, so the client will always require it.

The other option is http://ajax.googleapis.com/ajax/libs/jquery/x.x.x/jquery.min.js that has a 1year expire

So, someone know a cdn offering a jquery-latest.js with some cache time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

方觉久 2024-11-14 10:00:26

不会。

指定远期过期标头可以提高性能的原因是,如果该文件在过期时间范围内,浏览器可以立即使用该文件的本地副本。在这种情况下,浏览器根本不会发出 HTTP 请求,甚至不会检查 304“未修改”响应。

这意味着无法使用性能优化的过期标头来提供“最新版本”引用。如果是这样,就根本无法保证任何给定浏览器可能使用哪个版本的文件作为参考。

在生产中,您应该始终使用完全限定的 xyz 版本号,而不是“获取最新”引用之一。当您以这种方式引用时,Google 的 CDN 为 jQuery 提供 +1 年 过期标头,这与公共 CDN 的跨站点缓存潜力相结合,意味着您的许多用户可能永远不需要您网站上的 jQuery 的 HTTP 请求。

No.

The reason that specifying a far-future expires header improves performance is that the browser can immediately use a local copy of that file if it's within the expires timeframe. The browser won't make an HTTP request at all in that case, not even to check for a 304 "Not Modified" response.

That means a "latest version" reference cannot be served with a performance-optimized expires header. If it were, there would be no guarantee at all which version of the file any given browser might be using for the reference.

In production, you should always use the fully qualified x.y.z version number, and not one of the "get latest" references. Google's CDN serves jQuery with a +1 year expires header when you reference it that way, which combined with the cross-site caching potential of public CDNs, means that many of your users may never even need to make an HTTP request for jQuery on your site at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文