【发布时间】:2020-07-21 15:51:25
【问题描述】:
我已经对 .htaccess 文件进行了微调,但无法使杠杆浏览器缓存正常工作。 GTMetrix 告诉我几个 .png 和 .svg 图像没有设置过期。 1. Expires_module 已启用并在 Apache 中运行 2. Set Cache-Control 和 Enable Browser Cache 在.htaccess 中设置。 .htaccess 代码如下。欢迎任何使浏览器缓存工作的建议。 :-)
#Set Cache-Control
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|svg|js|css|swf)$">
Header set Cache-Control "max-age=84600, public"
#End Cache-Control
</FilesMatch>
#Enable browser cache
<IfModule mod_expires.c>
ExpiresActive On
# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"
# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
#End browser cache
#Enable HSTS
【问题讨论】:
标签: .htaccess caching browser controls mod-expires