Improve handling of gzipped built html/web applications

If gate jobs gzip their builds before they are uploaded or if the
builds are automatically gzipped after a while on logs.o.o, the
current configuration does not try to seek out the gzipped files
with the proper mimetypes.

This commit adds missing mimetypes for common files:
- css.gz
- js.gz
- ttf.gz (fonts)

It also adds a rewrite rule that will check if there is a .gz
equivalent for the file the user is trying to seek, if there is,
it will serve it - otherwise it's business as usual.

Change-Id: I5e5d2da0ef3c385f836507e69a686821aba925a1
This commit is contained in:
David Moreau-Simard 2016-11-10 17:50:19 -05:00
parent 4c672edab5
commit 7e1faac1fc
1 changed files with 21 additions and 1 deletions

View File

@ -16,13 +16,27 @@ NameVirtualHost <%= @vhost_name %>:<%= @port %>
# use Apache to compress the results afterwards, to save on the wire
# it's approx 18x savings of wire traffic to compress. We need to
# compress by content types that htmlify can produce
AddOutputFilterByType DEFLATE text/plain text/html
AddOutputFilterByType DEFLATE text/plain text/html application/x-font-ttf
<FilesMatch \.html\.gz$>
ForceType text/html
AddDefaultCharset UTF-8
AddEncoding x-gzip gz
</FilesMatch>
<FilesMatch \.css\.gz$>
ForceType text/css
AddDefaultCharset UTF-8
AddEncoding x-gzip gz
</FilesMatch>
<FilesMatch \.js\.gz$>
ForceType text/javascript
AddDefaultCharset UTF-8
AddEncoding x-gzip gz
</FilesMatch>
<FilesMatch \.ttf\.gz$>
ForceType application/x-font-ttf
AddEncoding x-gzip gz
</FilesMatch>
<Directory <%= @docroot %>>
Options <%= @options %>
AllowOverride None
@ -49,6 +63,12 @@ NameVirtualHost <%= @vhost_name %>:<%= @port %>
</Directory>
RewriteEngine On
# If the specified file does not exist, look if there is a gzipped version
# If there is, serve that one instead
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f
RewriteRule ^/(.*)$ %{REQUEST_URI}.gz
# rewrite txt.gz & console.html[.gz] files to map to our internal htmlify
# wsgi app
# PT, Pass-through: to come back around and get picked up by the