它是文件名或用作浏览器缓存的关键,整个网址是什么? [英] Is it the filename or the whole URL used as a key in browser caches?

查看:109
本文介绍了它是文件名或用作浏览器缓存的关键,整个网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是共同的希望浏览器缓存的资源 - 的JavaScript,CSS,图像等有新的版本,直到,然后确保浏览器获取并缓存新的版本,而不是

It's common to want browsers to cache resources - JavaScript, CSS, images, etc. until there is a new version available, and then ensure that the browser fetches and caches the new version instead.

的一个解决方案是嵌入在资源的文件名一个版本号,而将放置资源以这种方式进行管理的目录中具有版本号在它做同样的事情?是整个URL,以用作浏览器的缓存密钥的文件,或只是文件名本身以及一些元数据?

One solution is to embed a version number in the resource's filename, but will placing the resources to be managed in this way in a directory with a revision number in it do the same thing? Is the whole URL to the file used as a key in the browser's cache, or is it just the filename itself and some meta-data?

如果从获取我的code变化 /r20/example.js /r21/example.js ,我可以肯定的 example.js 修订20被缓存,但现在21版本已不是获取它,这就是缓存?

If my code changes from fetching /r20/example.js to /r21/example.js, can I be sure that revision 20 of example.js was cached, but now revision 21 has been fetched instead and it is now cached?

推荐答案

依赖。它应该是完整的URL,但有些浏览器(歌剧,Safari [2])应用不同的缓存策略对不同PARAMS的URL。

depends. it is supposed to be the full URL, but some browsers (Opera, Safari[2]) apply a different cache strategy for urls with different params.

最好的办法是修改文件的名称

有一个非常聪明的解决方案在这里(使用PHP,Apache)的

There is a very clever solution here (uses PHP, Apache)

http://verens.com/archives/2008 / 04/09 / JavaScript的缓存问题的解决/

战略说明:
根据HTTP缓存规范的字母,用户代理不应该缓存与查询字符串的URL。虽然Internet Explorer和Firefox忽略这一点,Opera和Safari不 - 要确保所有的用户代理可以缓存你的资源,我们需要不断的查询字符串了他们的URL

Strategy notes: "According the letter of the HTTP caching specification, user agents should never cache URLs with query strings. While Internet Explorer and Firefox ignore this, Opera and Safari don’t - to make sure all user agents can cache your resources, we need to keep query strings out of their URLs."

http://www.thinkvitamin.com/features/webapps/serving- JavaScript的快速

这篇关于它是文件名或用作浏览器缓存的关键,整个网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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