在 Chrome 中刷新后网站未加载 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15959862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:24:53  来源:igfitidea点击:

Website not loading CSS after refresh in Chrome

cssgoogle-chromewebrefreshloading

提问by Karlfromtheisland

So there is this site-> http://www.raudsilla.ee

所以有这个网站-> http://www.raudsilla.ee

This problem occurs only in Chrome- whenever you press refresh the page loses its CSS. Weird thing is that if you look the code of both- after and before refresh, they look exactly the same. And again, only happens in chrome.

此问题仅在 Chrome 中发生 - 每当您按刷新时,页面都会丢失其 CSS。奇怪的是,如果您查看刷新前后的代码,它们看起来完全一样。再说一次,只发生在 chrome 中。

I have tried quite may things, so far no luck... I wouldn't like to rule out anything at the moment, so any help appreciated.

我已经尝试了很多事情,到目前为止没有运气......我现在不想排除任何事情,所以任何帮助表示赞赏。

回答by Daniel Tavares

The browser is outputting javascript errors, if you check the code, you're calling jQuery's document ready before the script is loaded, as it says, "$ is not defined".

浏览器输出 javascript 错误,如果您检查代码,则在加载脚本之前调用 jQuery 的文档已准备就绪,正如它所说,“$ 未定义”。

After fixing the existing javascript error, it should load correctly.

修复现有的 javascript 错误后,它应该正确加载。

回答by Allard

I am seeing the same behavior on one of our own sites and started looking for a cause. The only conclusion I could come up with for now is that it is caused by the Mime Type of your stylesheet. This conclusion is supported by the behavior on our side.

我在我们自己的一个网站上看到了相同的行为,并开始寻找原因。我现在能得出的唯一结论是它是由样式表的 Mime 类型引起的。这一结论得到了我们这一方的行为的支持。

Update:There are three ways in which Chrome seems to load the CSS file:

更新:Chrome 似乎通过三种方式加载 CSS 文件:

  • As a fresh request, no cached version available, our server returns HTTP 200 OK, with content-type text/css. This works fine.
  • From the cache, without consulting the server. Chrome has cached content-type text/css. This works fine.
  • As a request with a cached version available. Our server returns HTTP 304 Not Modified, with content-type text/plain. This does not work.
  • 作为一个新的请求,没有可用的缓存版本,我们的服务器返回HTTP 200 OK,内容类型text/css。这工作正常。
  • 从缓存中,无需咨询服务器。Chrome 已缓存 content-type text/css。这工作正常。
  • 作为具有可用缓存版本的请求。我们的服务器返回HTTP 304 Not Modified,内容类型text/plain。这不起作用。

回答by Fernando Oliveira

After some crazy tests, I found the solution by adding "?" to the url css file.

经过一些疯狂的测试,我通过添加“?”找到了解决方案。到 url css 文件。

Example: href="../_css/setup_system.css?" type="text/css"

例子: href="../_css/setup_system.css?" type="text/css"

回答by dmcquay

site.css was not loading in Chrome. I added the ? in the CSS url and my styles started appearing.

site.css 未在 Chrome 中加载。我添加了?在 CSS url 中,我的样式开始出现。

回答by Larry

Shift + Refresh solves the problem so it must be a cache problem. PS . The site takes quite a long time to load, considered optimising?

Shift + Refresh 解决了问题,所以它一定是缓存问题。附注。该网站需要很长时间才能加载,考虑优化吗?

回答by Hamza Kouadri

desable addblock and refresh, if the website loaded correctly check the plugin

禁用 addblock 和刷新,如果网站加载正确检查插件

回答by Naresh Bisht

Open the console(ctrl + shift + c) and then network panel and check the disable cache button.

打开控制台(ctrl + shift + c),然后打开网络面板并检查禁用缓存按钮。

enter image description here

在此处输入图片说明