-
-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add serving pre-compressed content section (#136)
* added new serving pre-compressed content section * improve section * simplify FilesMatch regex * split each algorithm and move to build config * Add unit tests for pre-compressed content * added br and gz to FileMatchPattern * set utf-8 charset for .gz and .br JavaScript files * capital letters for utf-8 * remove blank * Use native httpd rules for type and charset definition * Fix gz type forced and document it Fix #134 and fix #105 and close #113 as per #105 (comment)
- Loading branch information
Showing
10 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# ---------------------------------------------------------------------- | ||
# | Brotli pre-compressed content | | ||
# ---------------------------------------------------------------------- | ||
|
||
# Serve brotli compressed CSS, JS, HTML, SVG, ICS and JSON files | ||
# if they exist and if the client accepts br encoding. | ||
# | ||
# (!) To make this part relevant, you need to generate encoded | ||
# files by your own. Enabling this part will not auto-generate | ||
# brotlied files. | ||
# | ||
# https://httpd.apache.org/docs/current/mod/mod_brotli.html#precompressed | ||
|
||
<IfModule mod_headers.c> | ||
|
||
RewriteCond %{HTTP:Accept-Encoding} br | ||
RewriteCond %{REQUEST_FILENAME}\.br -f | ||
RewriteRule \.(css|ics|js|json|html|svg)$ %{REQUEST_URI}.br [L] | ||
|
||
# Prevent mod_deflate double gzip | ||
RewriteRule \.br$ - [E=no-gzip:1] | ||
|
||
<FilesMatch "\.br$"> | ||
|
||
<IfModule mod_mime.c> | ||
# Serve correct content types | ||
AddType text/css css.br | ||
AddType text/calendar ics.br | ||
AddType text/javascript js.br | ||
AddType application/json json.br | ||
AddType text/html html.br | ||
AddType image/svg+xml svg.br | ||
|
||
# Serve correct content charset | ||
AddCharset utf-8 .css.br \ | ||
.ics.br \ | ||
.js.br \ | ||
.json.br | ||
</IfModule> | ||
|
||
# Force proxies to cache brotlied and non-brotlied files separately | ||
Header append Vary Accept-Encoding | ||
|
||
</FilesMatch> | ||
|
||
# Serve correct encoding type | ||
AddEncoding br .br | ||
|
||
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# ---------------------------------------------------------------------- | ||
# | GZip pre-compressed content | | ||
# ---------------------------------------------------------------------- | ||
|
||
# Serve gzip compressed CSS, JS, HTML, SVG, ICS and JSON files | ||
# if they exist and if the client accepts gzip encoding. | ||
# | ||
# (!) To make this part relevant, you need to generate encoded | ||
# files by your own. Enabling this part will not auto-generate | ||
# gziped files. | ||
# | ||
# https://httpd.apache.org/docs/current/mod/mod_deflate.html#precompressed | ||
# | ||
# (1) | ||
# Removing default MIME Type for .gz files allowing to add custom | ||
# sub-types. | ||
# You may prefer using less generic extensions such as .html_gz in | ||
# order to keep default behavior regarding .gz files. | ||
# https://httpd.apache.org/docs/current/mod/mod_mime.html#removetype | ||
|
||
<IfModule mod_headers.c> | ||
|
||
RewriteCond %{HTTP:Accept-Encoding} gzip | ||
RewriteCond %{REQUEST_FILENAME}\.gz -f | ||
RewriteRule \.(css|ics|js|json|html|svg)$ %{REQUEST_URI}.gz [L] | ||
|
||
# Prevent mod_deflate double gzip | ||
RewriteRule \.gz$ - [E=no-gzip:1] | ||
|
||
<FilesMatch "\.gz$"> | ||
|
||
# Serve correct content types | ||
<IfModule mod_mime.c> | ||
# (1) | ||
RemoveType gz | ||
|
||
# Serve correct content types | ||
AddType text/css css.gz | ||
AddType text/calendar ics.gz | ||
AddType text/javascript js.gz | ||
AddType application/json json.gz | ||
AddType text/html html.gz | ||
AddType image/svg+xml svg.gz | ||
|
||
# Serve correct content charset | ||
AddCharset utf-8 .css.gz \ | ||
.ics.gz \ | ||
.js.gz \ | ||
.json.gz | ||
</IfModule> | ||
|
||
# Force proxies to cache gzipped and non-gzipped files separately | ||
Header append Vary Accept-Encoding | ||
|
||
</FilesMatch> | ||
|
||
# Serve correct encoding type | ||
AddEncoding gzip .gz | ||
|
||
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
raw-content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
brotli-content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
raw-content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gzip-content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters