简体   繁体   English

硬重载加载新的 css 但 f5 加载旧版本(即使在硬重载之后)

[英]hard reload loads new css but f5 load the older version (even after the hard reload)

I have wagtail project, in this project I compile scss with webpack to the static folder in my project.我有 wagtail 项目,在这个项目中,我将带有 webpack 的 scss 编译到我项目中的 static 文件夹中。 When i have devtools open (and i checked the no cache checkbox) and then reload the page, the css is loaded.当我打开 devtools(并且我选中了无缓存复选框)然后重新加载页面时,css 被加载。 When i hard reload (clear cache etc) the new updated css is applied.当我硬重新加载(清除缓存等)时,应用新更新的 css。 If after this i press f5 again the previous older version is loaded.如果在此之后我再次按 f5,则会加载以前的旧版本。

How and why is this happening?这是如何以及为什么会发生的? This is the first time i've encountered this problem.这是我第一次遇到这个问题。

maybe it doesn't override the cache with the new css?也许它不会用新的 css 覆盖缓存?

I am running chrome version: 98.0.4758.109我正在运行 chrome 版本:98.0.4758.109

The browser is loading from the cache.浏览器正在从缓存中加载。 I had the same problem and the cleanest way that I found to solve it was adding the "version" to the files.我有同样的问题,我发现解决它的最干净的方法是将“版本”添加到文件中。 For example:例如:

<link rel="stylesheet" href="styles.css?v=1">

Obviously, when you want to upload it again, increase the number (v=2).显然,当你想再次上传时,增加数字(v=2)。

Eventually fixed this with adding hashes in the build files with webpack.最终通过使用 webpack 在构建文件中添加哈希来解决此问题。 So the filename wouldbe eg: main.2738547.css所以文件名例如: main.2738547.css

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

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