1
我试图用php minify为CSS/JS创建重写的URL。在tools.pingdom,我收到以下消息: 以下可缓存资源的新鲜度寿命较短。指定到期至少一周在未来以下资源:php minify - 通过浏览器重写URL缓存
http://www.xxx.xx/assets/minify/css-combined.css http://www.xxx.xx/assets/minify/js-combined.js
在根我有一个包含过期并且规则头的.htaccess:
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests
# in FF 3.6 (thx Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 1 month"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# RSS feed
ExpiresByType application/rss+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType font/truetype "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType font/woff "access plus 1 month"
ExpiresByType application/x-font-woff "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
# CSS and JavaScript
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
<IfModule mod_headers.c>
Header append Cache-Control "public"
Header append Vary User-Agent
<FilesMatch "\.(js|css|xml|gz|woff)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
在minify文件夹中有以下.htaccess规则:
RewriteEngine on
RewriteRule ^(.*).js$ index.php?g=$1
RewriteRule ^(.*).css$ index.php?g=$1
你能帮我吗?我究竟做错了什么?
谢谢=)
最好的问候, Russianroot
我想你必须在你的minify/index.php文件中添加标题。请参阅[本文](http://css-tricks.com/snippets/php/intelligent-php-cache-control/)了解如何做到这一点。原因是,即使浏览器请求.css或.js文件,因为请求已被重写,并且(假设您的index.php中没有适当的内容编码标头),您的请求并不会将所有缓存标题 – Prasanth 2014-11-01 13:59:59