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