Aug

18

Cache/GZip via .htaccess bei HostEurope

Immer mal wieder kommt es vor, das man die Einstellungen für das Caching in Proxys bzw. im Browser steuern möchte bzw. die Auslieferung der Daten in komprimierter Form erzwingen möchte… Für HostEurope verwende ich hierfür aktuell folgende Einstellungen via .htaccess:

# GZip
<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
    AddOutputFilterByType DEFLATE application/javascript application/x-javascript
    AddOutputFilterByType DEFLATE text/xml application/xml text/x-component application/json
    AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
    AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject font/truetype application/x-font-ttf font/opentype application/x-font-woff

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</IfModule>

# Proxy/Cache
<IfModule mod_expires.c>
    ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
    ExpiresDefault                          "access plus 1 month 1 hour"

# 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 month 1 hour"
    ExpiresByType application/atom+xml      "access plus 1 month 1 hour"

# Favicon (cannot be renamed)
    ExpiresByType image/x-icon              "access plus 1 week 1 hour" 

# Media: images, video, audio
    ExpiresByType image/gif                 "access plus 1 month 1 hour"
    ExpiresByType image/png                 "access plus 1 month 1 hour"
    ExpiresByType image/jpg                 "access plus 1 month 1 hour"
    ExpiresByType image/jpeg                "access plus 1 month 1 hour"
    ExpiresByType video/ogg                 "access plus 1 month 1 hour"
    ExpiresByType audio/ogg                 "access plus 1 month 1 hour"
    ExpiresByType video/mp4                 "access plus 1 month 1 hour"
    ExpiresByType video/webm                "access plus 1 month 1 hour"

# HTC files  (css3pie)
    ExpiresByType text/x-component          "access plus 1 month 1 hour"

# Webfonts
    ExpiresByType font/truetype             "access plus 1 month 1 hour"
    ExpiresByType application/x-font-ttf    "access plus 1 month 1 hour"
    ExpiresByType font/opentype             "access plus 1 month 1 hour"
    ExpiresByType application/x-font-woff   "access plus 1 month 1 hour"
    ExpiresByType image/svg+xml             "access plus 1 month 1 hour"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 month 1 hour"

# CSS and JavaScript
    ExpiresByType text/css "access plus 1 month 1 hour"
    ExpiresByType text/x-js "access plus 7 days 1 hour"
    ExpiresByType text/javascript "access plus 7 days 1 hour"
    ExpiresByType application/javascript "access plus 7 days 1 hour"
    ExpiresByType application/x-javascript "access plus 7 days 1 hour"

# Header
    <IfModule mod_headers.c>
        Header append Cache-Control "public"
    </IfModule>
</IfModule>

Die Einstellungen sind sicherlich nicht perfekt, aber sie funktionieren… und Tips bzw. Verbesserungsvorschläge sind natürlich gerne willkommen.

5 Kommentare bis jetzt

  1. Kommentar von mattiscb:

    Hallo,

    hast du auch mal geprüft, ob bei dir die expires-header überhaupt gesetzt werden? Bei Hosteurope ist mod_expires bei den Webpacks und Managed Servern gar nicht verfügbar … oder hast du andere Infos? Grüße aus Cottbus

  2. Kommentar von proog (splash):

    Hab gerade nochmal bei einer Seite nachgeschaut, und ja es funktioniert immer noch (ist irgendein WebPack).

  3. Kommentar von Patrick:

    Bei mir (Joomla Seite bei HostEurope in einem WebPack M) scheint mod_expires auch nicht zu laufen.

    Google PageSpeed zeigt jedenfalls auch mit dem Code in der htaccess „Ablauf nicht festgelegt“ für diverser Filetypen.

    Gruß
    Patrick

  4. Kommentar von Christian:

    Habe ebenfalls Probleme bei HostEurope: Laut phpinfo ist mod_expires zwar geladen – übrigens auf einem vServer Managed (jetzt: Webserver Basic), also einem etwas aufgebohrten Standard-Webpack.
    Aber sämtliche Expires-Einträge in der htaccess werden stumpf ignoriert. Andere Kommandos – z.B. Rewrite Rules – funktionieren dagegen problemlos.

  5. Kommentar von proog (splash):

    Bei der von mir kontrollierten Seite funktioniert noch immer alles Problemlos. Manchmal hilft es die Ergebnisse mit etwas Abstand zu kontrollieren (um mögliche Proxies/Caches zum umgehen, die anfangs noch ein falsches Ergebnis liefern könnten).

Kommentar hinterlassen

You must be logged in to post a comment.

Archiv

Zufällige Bilder

  • LED LENSER M7
  • Chinesischer Streifenhamster: Nils
  • Remedy Entertainment: Death Rally

Kommentare (28 Tage)

Sonstiges


Bloggeramt.de