2013-02-06 10 views
5

Ich habe Probleme mit der Verwendung von Browser-Caching. Ich habe diese .htaccess-Datei erstellt und verwende sie auf meinem Server, aber es scheint nicht zu funktionieren, ich kopierte dies von hier "http://www.samaxes.com/2011/05/improving-web-performance-with-apache-and-htaccess/". Ich mache am liebsten einen Grundfehler, also wäre jede Hilfe nett. Hier sind einige Details. Ich arbeite an einer Subdomain lasst es "Sub" und die Hauptdomain "Beispiel" nennen. also ich will alles in http://sub.example.com/ für die htaccess-Datei zu arbeiten. auf meinem Server habe ich die .htaccess-Datei in das Hauptverzeichnis von sub, das zum Beispiel das Hauptverzeichnis ist.htaccess für Leverage Browser-Caching funktioniert nicht

Ich habe einen Apache2 Server mit mod_headers und mod_expires aktiviert.

Prost.

<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

stoß immer noch suchen – clonerworks

Antwort

5

sieht sehr unordentlich aus.

Sie haben auch redundante Regeln wie

ExpiresByType application/javascript "access plus 216000 seconds"

und

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

Versuchen Sie, den Reiniger (und auf dem neuesten Stand) Regeln aus der html5-boilerplate oder Kasse alle h5bp server configs

0
mit

nur diesen verwenden und versuchen:

<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> 

Wie @Anthony Hatzopoulos darauf hingewiesen, Sie verwenden doppelte Konfigurationen und sie könnten widersprüchlich sein. Natürlich, wenn Sie möchten, können Sie auch "fileMatch" verwenden, aber die Sache ist, dass sie kein netter Code sind. Bitte beachten Sie, wenn Sie "fileMatch" verwenden, dann verwenden Sie den Code nicht.

Verwandte Themen