Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable GZip compression for Gitlab Pages?

When using Gitlab Pages to render my site which is slow in page-ranking. I can't find any solution on how to do following in GitLab (non-enterprise version)

  1. Specify HTTP Cache Headers for various page resources like for an image, so that it can be cached.

  2. Specify/Enable compression for GZip as page-ranking mentions compression disabled in gitlab.io.

like image 488
SACn Avatar asked May 05 '17 03:05

SACn


People also ask

How do I enable gzip compression on pages?

Gzip on Windows Servers (IIS Manager) Open up IIS Manager. Click on the site you want to enable compression for. Click on Compression (under IIS) Now Enable static compression and you are done!

Does GitHub pages gzip?

GitHub Pages currently support on-the-fly gzip compression. Since it's resource-intensive, usually the compression level is not set to high/max. Users can instead opt for pre-compressing the assets using the maximum compression level.

Is gzip compression enabled?

You can enable GZIP Compression on your site server by using, mod-deflate, or mod-zip method. If you are a professional coder, then you must have an idea that the deflate method has more advantages over mod-zip, as it compresses the output from your server before it is being sent to your user's browser.

How do I serve pre-compressed GZ files in GitLab pages?

GitLab Pages will serve pre-compressed .gz files that exist alongside uncompressed equivalents. A general solution that should work with most static publishing systems is to put this as the last step in the build process in .gitlab-ci.yml:

How do I enable gzip compression on a website?

Enter the URL to a webpage or resource, and type in gzip under "Accept-Encoding" to indicate that the HTTP client (i.e., the online testing tool in this case) accepts gzip compression, as most browsers do. You might review the other information and suggestions here to optimize serving as well.

How do I use GitLab pages?

To use GitLab Pages, you must create a project in GitLab to upload your website’s files to. These projects can be either public, internal, or private. GitLab always deploys your website from a very specific folder called public in your repository. When you create a new project in GitLab, a repository becomes available automatically.

Why is GitLab pages not working on nginx?

Introduced in GitLab 14.7. Reconfigure GitLab. You can also find the log file in /var/log/gitlab/gitlab-pages/current. It means you didn’t set the HTTP (S) protocol scheme in the Pages server settings. To fix it: In some cases, NGINX might default to using IPv6 to connect to the GitLab Pages service even when the server does not listen over IPv6.


2 Answers

  1. It looks like specifying HTTP Cache Headers is still not possible. But at least they have hardcoded "max-age=600" for all the resources here.
  2. You can compress contents of your public folder via .gitlab-ci.yml:

    script:

    • npm install
    • npm run build
    • gzip -k -6 -r public
like image 110
berzhy Avatar answered Nov 15 '22 07:11

berzhy


GitLab has support for serving compressed assets if you pre-compress them in the pages CI Job already. See the documentation.

Note that you can and also should use brotli compression as it's optimized for web content and supported by most modern browsers.

There is also a suggested snippet for your .gitlab-ci.yml:

pages:
  # Other directives
  script:
    # Build the public/ directory first
    - find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|css\)$' -exec gzip -f -k {} \;
    - find public -type f -regex '.*\.\(htm\|html\|txt\|text\|js\|css\)$' -exec brotli -f -k {} \;

I haven't found a way of influencing cache behavior. I am also looking for this.

like image 42
Scolytus Avatar answered Nov 15 '22 07:11

Scolytus