Aktive Gzip-Komprimierung

Avatar of Chris Coyier
Chris Coyier am

Komprimierung reduziert Antwortzeiten, indem die Größe der HTTP-Antwort verringert wird. Gzip ist die beliebteste und effektivste Komprimierungsmethode, die derzeit verfügbar ist, und reduziert die Antwortgröße im Allgemeinen um etwa 70 %.

Im Jahr 2009 reiste 90 % des Internetverkehrs über Browser, die Gzip unterstützten. Heute

Alle modernen Browser unterstützen die GZIP-Komprimierung und verhandeln sie automatisch für alle HTTP-Anfragen: Unsere Aufgabe ist es, sicherzustellen, dass der Server ordnungsgemäß konfiguriert ist, um die komprimierte Ressource bereitzustellen, wenn sie vom Client angefordert wird.

Auf einem Apache-basierten Server können Sie dies über die `.htaccess`-Datei tun

# BEGIN GZIP
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
# END GZIP

Dies ist im Wesentlichen eine Liste von MIME-Typen, auf die Gzipping dann angewendet wird. Sie können die Liste gerne für alle textbasierten Assets anpassen, die Sie bereitstellen.

Das HTML5 Boilerplate-Projekt bietet Serverkonfigurationen für alle gängigen Server. Dies ist seine Version für .htaccess

<IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE "application/atom+xml" \
                                  "application/javascript" \
                                  "application/json" \
                                  "application/ld+json" \
                                  "application/manifest+json" \
                                  "application/rdf+xml" \
                                  "application/rss+xml" \
                                  "application/schema+json" \
                                  "application/vnd.geo+json" \
                                  "application/vnd.ms-fontobject" \
                                  "application/x-font-ttf" \
                                  "application/x-javascript" \
                                  "application/x-web-app-manifest+json" \
                                  "application/xhtml+xml" \
                                  "application/xml" \
                                  "font/eot" \
                                  "font/opentype" \
                                  "image/bmp" \
                                  "image/svg+xml" \
                                  "image/vnd.microsoft.icon" \
                                  "image/x-icon" \
                                  "text/cache-manifest" \
                                  "text/css" \
                                  "text/html" \
                                  "text/javascript" \
                                  "text/plain" \
                                  "text/vcard" \
                                  "text/vnd.rim.location.xloc" \
                                  "text/vtt" \
                                  "text/x-component" \
                                  "text/x-cross-domain-policy" \
                                  "text/xml"

</IfModule>