在不使用过期的情况下利用浏览器缓存的正确方法是什么?
我不想使用过期,因为我不知道我的资源(css、js 等)多久会更改一次。一种情况可能是我将某些东西投入生产,但很快发现我的资源中有一些错误。因此,我修复了错误,然后将更新的资源投入生产,但它们在到期日期之前就已投入生产。如何强制浏览器使用更新的资源而不是缓存?
我不想使用指纹识别(基于版本类型的动态资源文件名),因为这些资源位于 svn 目录中。意思是,每次更改代码版本时,我都必须使用 svn 手动修改文件名(也许有一些可以自动执行此操作?)。
使用 http-equiv="last-modified"
将是首选选项,但这似乎无法正常工作。
也许我只是不知道这一切是如何运作的。请赐教。非常感谢。
-- 三
I don't want to use expiration, because I don't know how often my resources (css, js, etc) will change. A case might be where I push something to production, but soon find out I have some bugs in the resources. So I fixed the bugs, then push the updated resources into production, but they're in production before the expiration date. How do I force the browser to use the updated resources instead of cache?
I don't want to use fingerprinting (dynamic resource filename based of version type), because those resources are located in an svn directory. Meaning, I would have to manually modify the filename using svn every time I change the code version (maybe there's somewhat to automate this?).
Utilizing http-equiv="last-modified"
would be the preferred option, but that doesn't seem to work properly.
Also maybe I just don't know how all this works. Please enlighten me. Many thanks in advance.
-- Tri
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种选择是让所有对这些资源的引用都将版本号附加到查询字符串或 URL 中的其他位置,例如“styles/site.css?version=1.0”。这样,由于 URL 将在您的下一个版本中发生更改,因此您的浏览器会将其视为不同的 URL,并且不会使用缓存中的文件。
如果您更改为使用 CDN,将所有资源部署到版本编号的文件夹可以实现相同的目标。
One option would be to have all references to those resources to append a version number to the query string or elsewhere in the URL, for example "styles/site.css?version=1.0". That way, since the URL will change during your next release, your browser will see it as a different URL and will not use the file from cache.
If you ever change to using a CDN, deploying all resources to version numbered folders can achieve the same goal.