我正在尝试为我的 angular5 应用程序启用浏览器缓存。文件由 apache 提供
这是我在vhost
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/javascript "access 1 week"
ExpiresDefault "access 1 month"
</IfModule>
<IfModule mod_headers.c>
<filesmatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=2678400, public"
</filesmatch>
<filesmatch "\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesmatch>
<filesmatch "\.(pdf)$">
Header set Cache-Control "max-age=86400, public"
</filesmatch>
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=2678400, private"
</filesmatch>
</IfModule>
但我正在测试我的网站https://tools.pingdom.com/我收到了资产缓存失败的错误消息.js ,.css and .png
。
以下可缓存资源的新鲜度生命周期较短。请为以下资源指定至少一周后的过期时间:
更新
标题.js
HTTP/1.1 200 OK
Date: Fri, 17 Aug 2018 09:44:03 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Thu, 16 Aug 2018 11:25:11 GMT
ETag: "172da-5738bb238dfbb-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Strict-Transport-Security: max-age=631138519; includeSubDomains
Content-Length: 32241
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/javascript