Chrome不会缓存CSS文件。 .js文件工作正常 [英] Chrome will not cache CSS files. .js files work fine

查看:172
本文介绍了Chrome不会缓存CSS文件。 .js文件工作正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome不会在我的网站上缓存CSS文件,js文件也可以毫无问题地缓存,但是每次都会从服务器加载CSS。
服务器是IIS 8,在我的web.config中,我有:

Chrome will not cache the CSS files on my site, the js files are cached without issue, but the CSS is loaded from server every time. The server is IIS 8 and in my web.config I have:


  <location path="Content/dist">
<system.webServer>
  <staticContent>
    <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:15" />
  </staticContent>
</system.webServer>

将缓存设置为1天后过期。在我的CSS文件的标头中,我看到它已被采用,是这样的:

which sets the cache to expire in 1 day. in the header for my CSS files I can see that it has taken as there is this:


缓存控制:max-age = 86415

Cache-Control: max-age=86415

完整标头如下:

Accept-Ranges: bytes
Cache-Control: max-age=86415
Content-Encoding: gzip
Content-Length: 78464
Content-Type: text/css
Date: Thu, 16 Aug 2018 11:46:30 GMT
ETag: "053689a4935d41:0"
Last-Modified: Thu, 16 Aug 2018 10:12:14 GMT
Server: Microsoft-IIS/8.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET

在我的本地计算机上,按预期从高速缓存中读取文件,但是当我推送到服务器时,我却遇到了麻烦。这只是发生的CSS,web.config中引用的同一文件夹中的.js文件正在从缓存中加载。

On my local machine, the files are read from cache as expected, but when I push to the server I have the troubling behavior. Its just CSS that this is happening with, .js files from that same folder referenced in web.config are loading from cache. Here is the header from one such file.

Accept-Ranges: bytes
Cache-Control: max-age=86415
Content-Encoding: gzip
Content-Length: 3698
Content-Type: application/javascript
Date: Thu, 16 Aug 2018 11:45:44 GMT
ETag: "f7e1df9a4935d41:0"
Last-Modified: Thu, 16 Aug 2018 10:12:14 GMT
Server: Microsoft-IIS/8.5
Vary: Accept-Encoding
X-Powered-By: ASP.NET

Firefox也按照我的期望从缓存中加载文件。

Firefox loads the files from cache as I expect too.

https://gyazo.com/3ba41707c00e7fb539f6b84cc90f70e0

站点网址:

https://devworks.cashbackforex.com/

推荐答案

我遇到了类似的问题问题,结果是web.config的编制属性设置为debug = true,因为-

I faced similar kind of issue and turns out to be web.config's compilation attribute was set to debug=true, as-

< compilation debug = true>< / compilation>

它会导致文件既不捆绑也不缓存在浏览器上。只是删除debug = true解决了我的问题。所以我将其更改为-

It causes your files to neither be bundled nor cached on browser. Just removing debug=true resolved my issue. So I changed it to-

< compilation>< / compilation>

编辑-

特别是对于Chrome,它可能与您的证书有关。

For Chrome specifically, it could be related to your certificate.

Chrome浏览器不会缓存具有自签名证书的服务器 的资源。

Chrome does not cache resources from servers with self-signed certificate.

参见此处

这篇关于Chrome不会缓存CSS文件。 .js文件工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆