简体   繁体   English

Chrome 缓存就像一个疯狂的浏览器

[英]Chrome caching like a mad browser

I've got a web service that, like most others, uses js and css files.我有一个 web 服务,与大多数其他服务一样,它使用 js 和 css 文件。 I use the old trick of appending a version number to the js and css file like;我使用将版本号附加到 js 和 css 文件的旧技巧,例如; ?v=123 and that gets changed every time we update the service on production. ?v=123 并且每次我们更新生产服务时都会改变。

Now, this works fine on all browsers, except for Chrome.现在,这在除 Chrome 之外的所有浏览器上都可以正常工作。 Chrome seems to prefer it's cached version over getting the new one and therefor seems to ignore the appended variable. Chrome 似乎更喜欢它的缓存版本而不是获取新版本,因此似乎忽略了附加的变量。 In some cases, forcing it to refresh cache (cmd+r / ctrl+f5) wasn't enough so I had to go into options and clear out the cache for it to load up the new content.在某些情况下,强制它刷新缓存(cmd+r / ctrl+f5)是不够的,所以我必须将 go 放入选项中并清除缓存以加载新内容。

Has anyone experienced this issue with Chrome?有没有人在使用 Chrome 时遇到过这个问题? And if so, what was the resolution to the problem?如果是这样,问题的解决方案是什么?

Chrome should certainly treat requests with varying query strings as different requests; Chrome 当然应该将具有不同查询字符串的请求视为不同的请求; a cached result for style.css?v=123 should never be used for style.css?v=124 . style.css?v=123的缓存结果不应该用于style.css?v=124 If you're seeing different behavior, please file a bug at http://new.crbug.com/ and post the bug ID here.如果您看到不同的行为,请在http://new.crbug.com/ 提交错误并在此处发布错误 ID。

That said, I'd first check to see whether the page was cached longer than you expected.也就是说,我首先要检查页面的缓存时间是否比您预期的要长。 If a new version of the page itself wasn't downloaded, then it would still be requesting ?v=123 as the HTML wouldn't have changed.如果没有下载页面本身的新版本,那么它仍然会请求?v=123因为 HTML 不会改变。 If you're sending long-lived cache headers with the page, it's certainly possible that Chrome is caching it more aggressively than you expected.如果您要随页面发送长期缓存标头,那么 Chrome 的缓存速度肯定比您预期的更积极。 If that's the behavior you're seeing, please star http://crbug.com/8742 for updates.如果这是您看到的行为,请为http://crbug.com/8742 加注星标以获取更新。

I had also same experience我也有同样的经历

You can user Ctrl + Shift + R for cache free browsing in both Chrome + Mozilla.您可以使用 Ctrl + Shift + R 在 Chrome + Mozilla 中进行无缓存浏览。

I have had this experience as well.我也有过这样的经历。

I run a membership site which displays content such as "You must be logged in as a Gold member in order to see this content" if they are not logged in or are trying to view content not allowed by their membership level.我运行一个会员网站,如果他们未登录或试图查看其会员级别不允许的内容,则该网站会显示诸如“您必须以金卡会员身份登录才能查看此内容”之类的内容。 But even if the user is logged in, the user would still see "You need to log in", due to Google Chrome's aggressive caching.但即使用户已登录,用户仍会看到“您需要登录”,这是由于 Google Chrome 的积极缓存。 In Firefox, however, it works fine as I test logging in and out of all 5 levels of membership - each displaying the proper content.然而,在 Firefox 中,当我测试登录和退出所有 5 个会员级别时,它工作正常——每个级别都显示正确的内容。

While Chrome's caching problem can be solved by clearing the cache every time the user logs in and out, it would be really annoying to take that approach.虽然 Chrome 的缓存问题可以通过每次用户登录和注销时清除缓存来解决,但采用这种方法真的很烦人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM