Turbo für die Webseite – htaccess tunen, gzip injizieren und Ballast abwerfen

Mit Gzip und Deflate Compression übergewichtige Pfunde der Webseite schrumpfen sowie Müsli, ähm Cache und Expires gegen das Vergessen via htaccess optimal servieren – so gehts:
Ich habe schon lange nach einer optimalen htaccess gesucht, die möglichst alle (viele) Empfehlungen von PageSpeed sauber umsetzt. Wo wenn nicht bei google wurde ich heute endlich fündig!
Ich habe von der originalen htaccess Datei eine wichtige Teilmenge für mich abgezwackt, die all meinen Seiten ein paar Flügel verliehen hat!
Vielleicht kann der ein oder andere damit ja auch was gescheites anfangen:
1. Komprimieren der Inhalte mit Deflate nach Dateityp
# Deflate Compression by FileType <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-shockwave-flash </IfModule>
2. Komprimieren der Inhalte mit Deflate nach Dateiendungen. Zudem wir der Default Ablaufdatum (1 Monat) für das Caching der betroffenen Dateien gesetzt
# Deflate Compression by MimeType <IfModule mod_deflate.c> <FilesMatch "\.(js|jpg|jpeg|gif|png|css|txt|html)$"> ExpiresActive on ExpiresDefault "access plus 1 month" SetOutputFilter DEFLATE </FilesMatch> </IfModule>
3. Komprimieren der Inhalte mit gzip:
# gzip Compression if availiable <IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule>
4. Cache Ablauf auf einen Monat setzen
# turns cache on for 1 month <IfModule mod_expires.c> ExpiresActive On ExpiresByType text/css "access plus 1 month" ExpiresByType text/javascript "access plus 1 month" ExpiresByType text/html "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType application/x-javascript "access plus 1 month" ExpiresByType application/xhtml-xml "access plus 600 seconds" ExpiresByType image/gif "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/x-icon "access plus 1 month" </IfModule> <ifmodule mod_headers.c> <filesmatch "\\.(ico|jpe?g|png|gif|swf)$"> Header set Cache-Control "max-age=2592000, public" </filesmatch> <filesmatch "\\.(css)$"> Header set Cache-Control "max-age=604800, public" </filesmatch> <filesmatch "\\.(js)$"> Header set Cache-Control "max-age=216000, private" </filesmatch> <filesmatch "\\.(x?html?|php)$"> Header set Cache-Control "max-age=600, private, must-revalidate" </filesmatch> </ifmodule>
5. ETags deaktivieren
# Turn ETags Off <ifmodule mod_headers.c> Header unset ETag Header unset Last-Modified </ifmodule> FileETag None





Kommentar geschrieben am 30.11.2011
Danke Dir, ich kämpf zwar noch mit Gzip aber soweit funktioniert das erstmal.
Kommentar geschrieben am 30.11.2011
gzip ist nicht unbedingt auf jeden Server installiert…
Kommentar geschrieben am 27.04.2012
Hallo,
Also danke für die Mühe aber: Unter 5. schreibst du: ETags deaktivieren und Last-Modified ebenfalls.
Bei Google developpers heist es jedoch ausdrücklich: specify both Last-Modified and ETag. Das deaktivierst du aber hier ;-)
Kommentar geschrieben am 27.04.2012
Ja, Du hast Recht! Ich muss mal die Liste hier anpassen……
Gleich aufs ToDo setzen!