我正在优化一个网站,但我无法利用浏览器缓存.js
和.png
文件。
我的.htaccess
样子是这样的:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
<ifModule mod_expires>
ExpiresActive On
ExpiresDefault "access plus 5 days"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 60 days"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
ExpiresByType text/css "access plus 604800 seconds"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType text/x-javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
<FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
Header set Last-Modified "Mon, 31 Aug 2015 00:00:00 GMT"
</FilesMatch>
</ifModule>
缓存似乎可以与其他文件一起使用,但大多数分析工具都会显示如下错误消息:
以下可缓存资源的新鲜度生命周期较短。请为以下资源指定至少一周后的过期时间:
/css/images/skin/chebuoni1.jpg /images/logo-footer-mobile.png /images/logo-footer.png /js/cheSlider.js /js/home-modal.js /js/home.js /js/jquery.bxslider.js /js/menu.js /js/slider-hover.js /analytics.js /ga.js /js/browser-fix.js /js/click-hover.js /js/cookiechoices.js /js/jquery-1.8.2.min.js /js/lazysizes.min.js js/mobile-detect.js js/search.js
我尝试Last-Modified
通过.htaccess
各种.htaccess
配置添加和取消设置标头,但似乎没有任何反应。我不得不说,我的托管服务提供商在虚拟机上使用 CloudFlare。我做错了什么?
资源在我的浏览器中被正确缓存,但分析工具(tools.pingdom.com 和 google pagespeed insights)告诉我它们没有