Ecommerce, SEO, Gadgets, Mac und Internet Themen

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

Kategorie: web-development Autor: Viktor Dite

htaccess gzip compress
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

Bewertungen für: Turbo für die Webseite – htaccess tunen, gzip injizieren und Ballast abwerfen
1 Sterne2 Sterne3 Sterne4 Sterne5 Sterne ( 5,00 von maximal 5 Sternen aus 2 Bewertungen)
Loading ... Loading ...

Das könnte noch interessant sein:




4 Blog Kommentare

  1. azella:

    Danke Dir, ich kämpf zwar noch mit Gzip aber soweit funktioniert das erstmal.

  2. Viktor Dite:

    gzip ist nicht unbedingt auf jeden Server installiert…

  3. Sven:

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

  4. Viktor Dite:

    Ja, Du hast Recht! Ich muss mal die Liste hier anpassen……
    Gleich aufs ToDo setzen!


Autor dieses Blogs
Viktor Dite bei Google+ Viktor Dite bei Twitter

Webworker & Blogger