2013-02-06 14 views
5

Tôi đang gặp sự cố với việc tận dụng bộ nhớ đệm của trình duyệt. Tôi đã tạo tệp .htaccess này và đang sử dụng tệp này trên máy chủ của mình nhưng có vẻ như không hoạt động, tôi đã sao chép từ đây "http://www.samaxes.com/2011/05/improving-web-performance-with-apache-and-htaccess/". Tôi thực hiện một sai lầm cơ bản nhất vì vậy bất kỳ sự trợ giúp nào cũng sẽ tốt đẹp. dưới đây là một số chi tiết. Tôi đang làm việc trên một tên miền phụ cho phép gọi nó là "phụ" và tên miền chính "ví dụ". vì vậy tôi muốn mọi thứ trong http://sub.example.com/ để tệp htaccess hoạt động. trên máy chủ của tôi, tôi đã đặt tệp .htaccess trong thư mục chính của thư mục con, riêng biệt với thư mục chính.htaccess để tận dụng bộ đệm ẩn của trình duyệt không hoạt động

Tôi đang chạy máy chủ apache2 với cả mod_headers và mod_expires cũng được bật.

Chúc mừng.

<ifModule mod_deflate.c> 
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain 
AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml 
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml 
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json 
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf 
AddOutputFilterByType DEFLATE font/truetype font/opentype 
</ifModule> 
<ifModule mod_expires.c> 
ExpiresActive On 
ExpiresDefault "access plus 5 seconds" 
ExpiresByType image/x-icon "access plus 2592000 seconds" 
ExpiresByType image/jpeg "access plus 2592000 seconds" 
ExpiresByType image/png "access plus 2592000 seconds" 
ExpiresByType image/gif "access plus 2592000 seconds" 
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" 
ExpiresByType text/css "access plus 604800 seconds" 
ExpiresByType text/javascript "access plus 216000 seconds" 
ExpiresByType application/javascript "access plus 216000 seconds" 
ExpiresByType application/x-javascript "access plus 216000 seconds" 
ExpiresByType text/html "access plus 600 seconds" 
ExpiresByType application/xhtml+xml "access plus 600 seconds" 
</ifModule> 
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$"> 
Header set Cache-Control "max-age=2592000, private" 
Header set Expires "Sun, 17 July 2013 20:00:00 GMT" 
</filesMatch> 
<filesMatch "\\.(css|css.gz)$"> 
Header set Cache-Control "max-age=604800, private" 
</filesMatch> 
<filesMatch "\\.(js|js.gz)$"> 
Header set Cache-Control "max-age=604800, private" 
</filesMatch> 
<filesMatch "\\.(xml|txt)$"> 
Header set Cache-Control "max-age=216000, private, must-revalidate" 
</filesMatch> 
<filesMatch "\\.(html|htm)$"> 
Header set Cache-Control "max-age=7200, private, must-revalidate" 
</filesMatch> 
FileETag None 
+0

vết sưng vẫn đang tìm kiếm – clonerworks

Trả lời

5

trông rất lộn xộn.

Bạn cũng có những quy định không cần thiết như

ExpiresByType application/javascript "access plus 216000 seconds"

<filesMatch "\\.(js|js.gz)$"> 
Header set Cache-Control "max-age=604800, private" 
</filesMatch> 

Hãy thử sử dụng sạch hơn (và cập nhật) quy tắc từ html5-boilerplate hoặc kiểm tất cả các h5bp server configs

0

chỉ sử dụng cái này và thử:

<ifModule mod_expires.c> 
ExpiresActive On 
ExpiresDefault "access plus 5 seconds" 
ExpiresByType image/x-icon "access plus 2592000 seconds" 
ExpiresByType image/jpeg "access plus 2592000 seconds" 
ExpiresByType image/png "access plus 2592000 seconds" 
ExpiresByType image/gif "access plus 2592000 seconds" 
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" 
ExpiresByType text/css "access plus 604800 seconds" 
ExpiresByType text/javascript "access plus 216000 seconds" 
ExpiresByType application/javascript "access plus 216000 seconds" 
ExpiresByType application/x-javascript "access plus 216000 seconds" 
ExpiresByType text/html "access plus 600 seconds" 
ExpiresByType application/xhtml+xml "access plus 600 seconds" 
</ifModule> 

Giống như @Anthony Hatzopoulos đã chỉ ra, bạn đang sử dụng cấu hình trùng lặp và chúng có thể xung đột nhau. Tất nhiên nếu bạn thích bạn có thể sử dụng "fileMatch" cách là tốt, nhưng điều này là họ không phải là mã tốt đẹp. Xin lưu ý nếu bạn sử dụng "fileMatch" thì bạn không sử dụng mã.

Các vấn đề liên quan