我已將我網站上的所有JS設置爲緩存一週。但是,我需要以更高的頻率刷新特定的文件。因此,我已經使用FilesMatch以實現例外我的.htaccess文件:在瀏覽器中未反映的htaccess Expires標題中的更改
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 year"
# Data interchange
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
# Favicon (cannot be renamed!)
ExpiresByType image/x-icon "access plus 1 week"
# HTML components (HTCs)
ExpiresByType text/x-component "access plus 1 month"
# HTML
ExpiresByType text/html "access plus 0 seconds"
# JavaScript
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
# Manifest files
ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Media
ExpiresByType audio/ogg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType video/mp4 "access plus 1 month"
ExpiresByType video/ogg "access plus 1 month"
ExpiresByType video/webm "access plus 1 month"
# Web feeds
ExpiresByType application/atom+xml "access plus 1 hour"
ExpiresByType application/rss+xml "access plus 1 hour"
# Web fonts
ExpiresByType application/font-woff "access plus 1 month"
ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
ExpiresByType application/x-font-ttf "access plus 1 month"
ExpiresByType font/opentype "access plus 1 month"
ExpiresByType image/svg+xml "access plus 1 month"
</IfModule>
<FilesMatch "^(ga\.js)$">
ExpiresActive on
ExpiresDefault "access plus 2 days"
</FilesMatch>
例外文件是在/sandboxassets/js/ga.js
和的.htaccess我一起工作是在文檔根目錄(/
)。但是,瀏覽器似乎並沒有履行這一異常,並提供下列頭有問題的文件:
Accept-Ranges:bytes
Access-Control-Allow-Origin:*
Age:0
Cache-Control:max-age=604800
Content-Encoding:gzip
Content-Length:11967
Content-Type:application/javascript
Date:Thu, 02 Mar 2017 15:03:55 GMT
Expires:Thu, 09 Mar 2017 15:03:55 GMT
Last-Modified:Thu, 02 Mar 2017 15:00:01 GMT
Server:Apache Phusion_Passenger/4.0.10 mod_bwlimited/1.4 mod_fcgid/2.3.9
Vary:Accept-Encoding,User-Agent
Via:1.1 varnish-v4
X-Varnish:18808880
604800秒在1周這是我的.htaccess中定義的所有JS資產默認但我需要172800秒(2天)。我究竟做錯了什麼?另外,有什麼辦法可以告訴瀏覽器刷新到最新的頭文件嗎? Opera將返回一個31536000秒(1年),這是我最近更改爲1周所有JS的!
更新:使用下面的代碼導致我的網站與錯誤完全打破500:
<Directory "/sandboxassets/js/">
AllowOverride All
<FilesMatch "ga\.js$">
Expires A172800
</FilesMatch>
<FilesMatch "tww\.js$">
Expires A172800
</FilesMatch>
</Directory>
我第一次加入這裏面<IfModule mod_expires.c>
,然後緊隨其後,每一次經歷了同樣的錯誤。
此代碼完全破壞我的網站。我用我使用的確切代碼更新了問題。 – TheLearner
呃。對於那個很抱歉。我會四處探索,看看我還能找到什麼。 – malodie