2011-07-22 37 views
2

我從Google Speed測試中得到這個錯誤:Google Speed利用瀏覽器緩存

以下可緩存資源的新鮮度生存期較短。爲以下資源指定將來至少一週的到期日期:

http://localhost/english/favicon.ico (expiration not specified) 
http://localhost/english/images/bg_center.png (expiration not specified) 
http://localhost/english/images/bg_top.jpeg (expiration not specified) 
http://localhost/english/images/footer_bg2.png (expiration not specified) 
http://localhost/english/images/m_facebook.png (expiration not specified) 
http://localhost/english/images/m_rss.png (expiration not specified) 
http://localhost/english/images/top_bg.png (expiration not specified) 
http://localhost/english/javascript/gram.js (expiration not specified) 
http://localhost/english/javascript/top_start.js (expiration not specified) 
http://localhost/english/jquery.js (expiration not specified) 
http://localhost/english/style/gram.css (expiration not specified) 
http://localhost/english/style/style.css (expiration not specified) 

我應該在我的htaccess文件中執行某些操作嗎?

回答

4

看起來像靜態文件沒有設置過期。閱讀 - http://www.absolutelytech.com/2010/08/02/howto-add-expire-headers-to-cache-static-files-using-htaccess/

你需要

# Turn on the Expires engine 
ExpiresActive On 

# Expires after a month client accesses the file 
ExpiresByType image/jpeg A2592000 
ExpiresByType image/gif A2592000 
ExpiresByType image/png A2592000 
ExpiresByType image/x-icon A2592000 
ExpiresByType text/plain A2592000 

# Good for one week 
ExpiresByType application/x-javascript M604800 
ExpiresByType text/css M604800 
ExpiresByType text/html M604800 
+0

如何使用web.config文件做呢? (在Windows中),這可以在共享託管中完成嗎? – Benny

+0

我對windows系統沒有多少了解。如果它是主機提供商沒有限制的目錄特定配置,它也應該在共享主機環境中工作。 – Sukumar

0

的PageSpeed張貼下面的代碼在你的.htaccess:利用瀏覽器緩存 每次瀏覽器加載它有一個網頁,下載所有網頁文件才能正常顯示頁面。這包括所有的HTML,CSS,JavaScript和圖像。

要啓用瀏覽器緩存,您需要編輯您的HTTP標頭以設置特定類型文件的到期日期。

在你的域的根目錄下找到你的.htaccess文件,這個文件是一個隱藏文件,但是應該顯示在FileZilla或CORE等FTP客戶端中。您可以使用記事本或任何形式的基本文本編輯器來編輯htaccess文件。

## EXPIRES CACHING ## 
 
<IfModule mod_expires.c> 
 
ExpiresActive On 
 
ExpiresByType image/jpg "access plus 1 year" 
 
ExpiresByType image/jpeg "access plus 1 year" 
 
ExpiresByType image/gif "access plus 1 year" 
 
ExpiresByType image/png "access plus 1 year" 
 
ExpiresByType text/css "access plus 1 month" 
 
ExpiresByType application/pdf "access plus 1 month" 
 
ExpiresByType text/x-javascript "access plus 1 month" 
 
ExpiresByType application/x-shockwave-flash "access plus 1 month" 
 
ExpiresByType image/x-icon "access plus 1 year" 
 
ExpiresDefault "access plus 2 days" 
 
</IfModule> 
 
## EXPIRES CACHING ##