服务器是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/