Umso schneller deine Webseite geladen ist – umso besser, sowohl für das Ranking in Google, als auch für den Benutzer.
Für eine Maximierung der Webseite Geschwindigkeit ist das Leverage Browser Caching eine ausgezeichnete Wahl.
Also speichern Sie statische oder nur selten geänderte Ressourcen für einen Zeitraum im lokalen Speicher zwischen.
Dies reduziert die Serveranfragen und lässt unsere Webseite deutlich performanter werden.
Hierzu haben Sie die Möglichtkeit das Browser-Caching in unserer .htaccess zu aktivieren.
Vorab sollten Sie die .htaccess sicherheitshalber abspeichern.
Die .htaccess Datei befindet sich in der Regel im Basisverzeichnis der Website (Zielpfad der Domain).
Sie wird bei jedem Aufruf des Apache Webservers und für jede einzelne Komponente der Webseite ausgewertet.
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault „access plus 1 month“
# Data
ExpiresByType text/xml „access plus 0 seconds“
ExpiresByType text/html „access plus 0 seconds“
ExpiresByType text/plain „access plus 0 seconds“
ExpiresByType application/xml „access plus 0 seconds“
ExpiresByType application/json „access plus 0 seconds“
ExpiresByType application/rss+xml „access plus 1 hour“
ExpiresByType application/atom+xml „access plus 1 hour“
ExpiresByType text/x-component „access plus 1 hour“
# Web-App-Manifeste
ExpiresByType application/x-web-app-manifest+json „access plus 0 seconds“
ExpiresByType text/cache-manifest „access plus 0 seconds“
# Scripts
ExpiresByType text/css „access plus 1 month“
ExpiresByType text/javascript „access plus 1 month“
ExpiresByType application/javascript „access plus 1 month“
ExpiresByType application/x-javascript „access plus 1 month“
# Bilder
ExpiresByType image/gif „access plus 1 month“
ExpiresByType image/png „access plus 1 month“
ExpiresByType image/jpe „access plus 1 month“
ExpiresByType image/jpg „access plus 1 month“
ExpiresByType image/jpeg „access plus 1 month“
ExpiresByType image/jp2 „access plus 1 month“
ExpiresByType image/pipeg „access plus 1 month“
ExpiresByType image/bmp „access plus 1 month“
ExpiresByType image/tiff „access plus 1 month“
ExpiresByType image/svg+xml „access plus 1 month“
ExpiresByType image/vnd.microsoft.icon „access plus 1 month“
# Icons
ExpiresByType image/ico „access plus 1 month“
ExpiresByType image/icon „access plus 1 month“
ExpiresByType text/ico „access plus 1 month“
ExpiresByType image/x-ico „access plus 1 month“
ExpiresByType image/x-icon „access plus 1 month“
ExpiresByType application/ico „access plus 1 month“
# Schriftarten
ExpiresByType font/truetype „access plus 1 month“
ExpiresByType font/opentype „access plus 1 month“
ExpiresByType application/x-font-ttf „access plus 1 month“
ExpiresByType application/x-font-woff „access plus 1 month“
ExpiresByType application/font-woff „access plus 1 month“
ExpiresByType application/vnd.ms-fontobject „access plus 1 month“
# Sonstiges
ExpiresByType application/pdf „access plus 1 month“
ExpiresByType image/vnd.wap.wbmp „access plus 1 month“
ExpiresByType application/vnd.wap.wbxml „access plus 1 month“
ExpiresByType application/smil „access plus 1 month“
</IfModule>
„IfModule“ prüft ob das benötigte Modul „mod_expires“ aktiviert ist. Der Befehl „ExpiresByType“ spricht dann einzelne Medientyp an.
„Access plus 1 month“ legt die Dauer fest, wie lang die Ressource zwischengespeichert werden soll.
ExpiresDefault „access plus 1 month“ legt den Standard fest.
Zu diesen Ressourcen zählen .gif, .jpg und .png, .css, .js, .pdf, SWF-Datein und einige weitere.
Für die verschiedenen Dateitypen legen Sie individuelle Ablaufdaten fest.
Laut Google sollten die meisten Caching Ressourcen eine Mindestdauer von einer Woche betragen.
Letztendlich muss jeder für sich selbst wissen, was er wie lange zwischenspeichern möchte.
Bei der Aktivierung werden folgende Header an den Browsergesendet
– Cache-Control-Header & Expires-Header – Gültigkeitsdauer
– Last-Modified-Header & E-Tag-Header – Ressourcen Validierung
Ob die Aktivierung tatsächlich funktioniert hat, kann man ganz einfach mithilfe folgender Tools prüfen
– Google Insights
– GTmetrix
– Pingdom