2016-04-20 17 views
8

Tôi đang sử dụng thông tin chi tiết về tốc độ trang của Google để cải thiện hiệu suất nhưng không có vấn đề gì tôi không thể 'tận dụng bộ nhớ đệm trình duyệt' để biến mất.Tận dụng bộ nhớ đệm của trình duyệt - cập nhật không hoạt động

Tôi đã sửa đổi tệp htaccess như được mô tả trên một số bài viết trực tuyến và thêm mọi kết hợp tôi có thể. Trong thông tin chi tiết về trang, nó phàn nàn về các tệp CSS/PNG/JS/JPG.

# Expires Caching Start # 
<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresByType text/css "access 2 day" 
ExpiresByType text/html "access 2 day" 
ExpiresByType image/gif "access 1 year" 
ExpiresByType image/png "access 1 year" 
ExpiresByType image/jpg "access 1 year" 
ExpiresByType image/jpeg "access 1 year" 
ExpiresByType image/x-icon "access 1 year" 
ExpiresByType application/pdf "access 1 month" 
ExpiresByType application/javascript "access 1 month" 
ExpiresByType text/x-javascript "access 1 month" 
ExpiresByType application/x-shockwave-flash "access 1 month" 
ExpiresDefault "access 1 month" 
ExpiresByType text/x-javascript "access plus 1 month" 
ExpiresByType application/x-javascript "access plus 1 month" 
ExpiresByType text/x-javascript "access 1 month" 
</IfModule> 
# Expires Caching End # 

Trả lời

6

Bạn dường như thiếu bạn cộng trong "quyền truy cập cộng thêm 1 tháng" trong nhiều dòng. Mặc định nên dòng thứ hai của bạn để có thể đọc

Dưới đây là một phần của mẫu h5bp:

ExpiresActive on 
ExpiresDefault          "access plus 1 month" 
ExpiresByType text/css        "access plus 1 year" 
ExpiresByType text/html        "access plus 0 seconds" 
ExpiresByType application/javascript    "access plus 1 year" 
ExpiresByType application/x-javascript    "access plus 1 year" 
ExpiresByType text/javascript      "access plus 1 year" 

... https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

5

Nếu bạn đang sử dụng Apache, bạn có thể muốn chạy các vì điều này làm việc cho tôi:

sudo a2enmod headers 
sudo a2enmod expires 
service apache2 restart 

Bạn cũng có thể thử mã này:

## 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 ## 
+0

Đó là mã dường như không khác nhau nhiều với những gì tôi có rồi. – connersz

+0

@connersz Bạn đã thử chạy các lệnh chưa? – Edward

0

Có thể thử này:

# 1 Month for most static assets 
<filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$"> 
Header set Cache-Control "max-age=2592000, public" 
</filesMatch> 
Các vấn đề liên quan