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
pagessite we compress some resources withgzip; - Later when the
pages daemonservers requests it will check if the HTTP client acceptsgzipcompressed responses; - If client accepts
gzipresponses and gzipped version exists serve him the precompressedgzipfile; - If client doesn't accept
gzipresponse or given resource doesn't have precompressedgzipfile 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
gzipand notdeflate: http://stackoverflow.com/questions/388595/why-use-deflate-instead-of-gzip-for-text-files-served-by-apache - Generating the
.gzis very easy with.gitlab-ci.yml: https://gitlab.com/zloster/zloster.gitlab.io/blob/master/.gitlab-ci.yml#L6-9