2012-03-14 34 views
0

我在我的網站上設置了一個子域,純粹是爲了提高網站速度(在Google推薦的多個無Cookie域中傳播HTTP請求)。我一直在做實驗,看起來我的.htaccess緩存設置在子域上沒有相同的效果。.htaccess跨子域緩存問題

比較這兩個URL,且他們的反應/緩存時間:

http://www.scenepointblank.com/assets/img/features/coming_in_2012_homepage.png(原件) http://img.scenepointblank.com/features/coming_in_2012_homepage.png(子域)

看着它似乎已經拿起相同cache_control響應報頭,但實際響應時間變化相當大(我看到www的平均值爲〜400ms,img的值爲〜4s)。

我的.htaccess文件位於域的根目錄下,爲了實驗,我還在scenepointblank.com/assets/img/中添加了一個副本,但沒有任何效果。該文件的內容如下:

FileETag MTime Size 
<IfModule mod_expires.c> 
# Enable expirations. 
ExpiresActive On 

# Cache all files for 2 weeks after access (A). 
ExpiresDefault A1209600 

<FilesMatch .php$> 
# Do not allow PHP scripts to be cached unless they explicitly send cache 
# headers themselves. Otherwise all scripts would have to overwrite the 
# headers set by mod_expires if they want another caching behavior. 
ExpiresActive Off 
</FilesMatch> 
</IfModule> 

# 480 weeks 
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> 
Header set Cache-Control "max-age=290304000, public" 
</FilesMatch> 

任何想法,爲什麼會發生這種情況?

+0

只注意到的子域的一個返回HTTP 200,但在WWW上的一個返回304想這是有關... – 2012-03-14 22:52:22

回答

1

似乎通過將以下爲.htaccess有固定的:

ExpiresActive On 
ExpiresByType image/png "now plus 365 days" 
ExpiresByType image/jpeg "now plus 365 days" 
ExpiresByType image/gif "now plus 365 days" 
ExpiresByType text/css "now plus 365 days"