代码之家  ›  专栏  ›  技术社区  ›  Kevin Bradshaw

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

  •  1
  • Kevin Bradshaw  · 技术社区  · 6 年前

    服务器是IIS 8,在我的web.config中有:

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

    将缓存设置为在1天内过期。在我的CSS文件的标题中,我可以看到它是这样的:

    缓存控制:最大年龄=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文件上。这是一个这样的文件的头。

    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

    https://devworks.cashbackforex.com/

    1 回复  |  直到 6 年前
        1
  •  2
  •   soccer7    6 年前

    我遇到了类似的问题,结果是web.config的compilation属性设置为debug=true,如下所示-

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

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

    <compilation></compilation>

    编辑-

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

    Chrome不缓存来自服务器的资源 .

    See here