Hallo Forum,
ich beschäftige mich seit einer Weile mit Caching und den damit einhergehenden Problemen. Nach dem CMS, OpCache und Konsorten, bin ich jetzt bei der .htaccess und den Caching Anweisungen für den Browser angelangt und habe ein paar Verständnisfragen und hoffe, ihr könnt mir helfen.
Von vielen Tutorials wird folgende Vorgehensweise empfohlen:
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
# Your document html
ExpiresByType text/html "access plus 0 seconds"
# Data
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
# Feed
ExpiresByType application/rss+xml "access plus 1 hour"
ExpiresByType application/atom+xml "access plus 1 hour"
# Favicon (cannot be renamed)
ExpiresByType image/x-icon "access plus 1 week"
# Media: images, video, audio
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType video/ogg "access plus 1 year"
ExpiresByType audio/ogg "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/webm "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
# HTC files (css3pie)
ExpiresByType text/x-component "access plus 1 month"
# Webfonts
ExpiresByType application/font-ttf "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType font/eot "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/eot "access plus 1 year"
# CSS and JavaScript
ExpiresByType text/css "access plus 6 month"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/ld+json "access plus 0 seconds"
ExpiresByType application/schema+json "access plus 0 seconds"
ExpiresByType application/vnd.geo+json "access plus 0 seconds"
# Other
ExpiresByType text/x-cross-domain-policy "access plus 1 week"
</IfModule>
Alles anzeigen
Andere favorisieren mod_headers wie bspw:
<IfModule mod_headers.c>
<FilesMatch "\.(svg|js|css|gif|png|jpg|jpeg|txt|woff2|woff|webp|txt|ico)$">
Header set Cache-Control "max-age=31536000, immutable"
</FilesMatch>
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=120, private, proxy-revalidate"
</FilesMatch>
# NONE
<FilesMatch "\.(pl|php|cgi|spl)$">
Header unset Cache-Control
Header unset Expires
Header unset Last-Modified
FileETag None
Header unset Pragma
</FilesMatch>
</IfModule>
Alles anzeigen
Ein paar wenige empfehlen den ETag komplett zu eliminieren:
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
Andere wiederum kombinieren mod_headers und mod_expires, sodass man zunächst einmal verwirrt ist, wenn man sich damit näher beschäftigen möchte.
Für mich stellt sich das im Moment so dar, dass wenn man mod_expires einsetzt, auf die zweite Methode wie mod_headers komplett verzichten kann.
Wie seht ihr das und habt ihr mir vielleicht auch gute Quellen, wo man sich (außer Apache - die kenne ich schon) tieferes Wissen aneignen kann. Oder kennt ihr auch ein Beispiel einer guten Umsetzung?
Schöne Grüße in die Runde