Chrome 不会缓存 CSS 个文件。 .js 文件工作正常

Chrome will not cache CSS files. .js files work fine

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

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

设置缓存在 1 天后过期。在我的 CSS 文件的 header 中,我可以看到它已被占用,因为有这个:

Cache-Control: max-age=86415

完整的header如下:

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 文件正在从缓存中加载。这是其中一个文件的 header。

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 也如我所料从缓存中加载文件。

https://gyazo.com/3ba41707c00e7fb539f6b84cc90f70e0

站点 URL :

https://devworks.cashbackforex.com/

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

<compilation debug="true"></compilation>

它会导致您的文件既不被捆绑也不缓存在浏览器上。只需删除 debug=true 即可解决我的问题。所以我把它改成了-

<compilation></compilation>

编辑-

对于 Chrome 具体而言,它可能与您的证书有关。

Chrome 不缓存来自服务器 具有自签名证书 .

的资源

See here