缓存静态内容
我试图了解为静态内容(图像、CSS、JavaScript)设置的最佳 Cache-Control
值是什么。问题是我的 JavaScript/CSS 仍处于开发阶段,每当我进行更改时,我希望人们立即看到更改(他们不应该重新加载缓存)。
解决这个问题的最佳方法是什么?我是否应该在每个静态请求后添加 ?version=1000202210
以便浏览器知道它是新的?
I'm trying to understand what's the best Cache-Control
value to be set for static content (images, css, javascript). The issue with this is that my JavaScript/CSS is still very much in development, and whenever I make a change I want people to see changes immediately (they shouldn't have to reload their cache).
What's the best way to go about this? Should I add a ?version=1000202210
after each static request so the browser knows it's new?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,较长的有效期+指纹识别可以为您带来最大的浏览器缓存,同时具有立即传播更改所需的灵活性。 Google 页面速度有很好的解释。您可以在查询字符串或资产路径中添加指纹。只要当您希望再次获取资源时 URL 发生变化,如何执行并不重要。
Yes, a long expiration date + fingerprinting brings you maximal browser caching and at the same time the necessary flexibility to propagate changes immediately. Google page speed has a good explanation. You can either add a fingerprint in the query string or in the path of the assets. It doesn't really matter how you do it as long as the URL changes when you want the resource to be fetched again.