|
| 1 | +# ---------------------------------------------------------------------- |
| 2 | +# | GZip pre-compressed content | |
| 3 | +# ---------------------------------------------------------------------- |
| 4 | + |
| 5 | +# Serve gzip compressed CSS, JS, HTML, SVG, ICS and JSON files |
| 6 | +# if they exist and if the client accepts gzip encoding. |
| 7 | +# |
| 8 | +# (!) To make this part relevant, you need to generate encoded |
| 9 | +# files by your own. Enabling this part will not auto-generate |
| 10 | +# gziped files. |
| 11 | +# |
| 12 | +# https://httpd.apache.org/docs/current/mod/mod_deflate.html#precompressed |
| 13 | +# |
| 14 | +# (1) |
| 15 | +# Removing default MIME Type for .gz files allowing to add custom |
| 16 | +# sub-types. |
| 17 | +# You may prefer using less generic extensions such as .html_gz in |
| 18 | +# order to keep default behavior regarding .gz files. |
| 19 | +# https://httpd.apache.org/docs/current/mod/mod_mime.html#removetype |
| 20 | + |
| 21 | +<IfModule mod_headers.c> |
| 22 | + |
| 23 | + RewriteCond %{HTTP:Accept-Encoding} gzip |
| 24 | + RewriteCond %{REQUEST_FILENAME}\.gz -f |
| 25 | + RewriteRule \.(css|ics|js|json|html|svg)$ %{REQUEST_URI}.gz [L] |
| 26 | + |
| 27 | + # Prevent mod_deflate double gzip |
| 28 | + RewriteRule \.gz$ - [E=no-gzip:1] |
| 29 | + |
| 30 | + <FilesMatch "\.gz$"> |
| 31 | + |
| 32 | + # Serve correct content types |
| 33 | + <IfModule mod_mime.c> |
| 34 | + # (1) |
| 35 | + RemoveType gz |
| 36 | + |
| 37 | + # Serve correct content types |
| 38 | + AddType text/css css.gz |
| 39 | + AddType text/calendar ics.gz |
| 40 | + AddType text/javascript js.gz |
| 41 | + AddType application/json json.gz |
| 42 | + AddType text/html html.gz |
| 43 | + AddType image/svg+xml svg.gz |
| 44 | + |
| 45 | + # Serve correct content charset |
| 46 | + AddCharset utf-8 .css.gz \ |
| 47 | + .ics.gz \ |
| 48 | + .js.gz \ |
| 49 | + .json.gz |
| 50 | + </IfModule> |
| 51 | + |
| 52 | + # Force proxies to cache gzipped and non-gzipped files separately |
| 53 | + Header append Vary Accept-Encoding |
| 54 | + |
| 55 | + </FilesMatch> |
| 56 | + |
| 57 | + # Serve correct encoding type |
| 58 | + AddEncoding gzip .gz |
| 59 | + |
| 60 | +</IfModule> |
0 commit comments