Enable gitlab-pages daemon to send precompressed .gz files as response if they are available
The idea is very simple and borrowed from ngx_http_gzip_static_module. Why? Because this will lower the required bandwidth for the pages sites and will help them load faster. Also serving precompiled gzip files will not require additional CPU
resources on the server but only from the CI machine
.
Basic steps:
- In the deployment phase of
pages
site we compress some resources withgzip
; - Later when the
pages daemon
servers requests it will check if the HTTP client acceptsgzip
compressed responses; - If client accepts
gzip
responses and gzipped version exists serve him the precompressedgzip
file; - If client doesn't accept
gzip
response or given resource doesn't have precompressedgzip
file serve the original file;
Required changes:
I don't know go
code but it seem that only changing domain.go will need to be changed. The two functions serveFile
and serveCustomFile
could check for .gz
version of the requested file if the HTTP request has Accept-Encoding: gzip
and then serve it. If it doesn't exist try to serve the normal version. The unknown part (for me) is the handling of the Content-encoding: gzip
for the response.
Some additional information:
- Why
gzip
and notdeflate
: http://stackoverflow.com/questions/388595/why-use-deflate-instead-of-gzip-for-text-files-served-by-apache - Generating the
.gz
is very easy with.gitlab-ci.yml
: https://gitlab.com/zloster/zloster.gitlab.io/blob/master/.gitlab-ci.yml#L6-9