Reputation: 1924
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)
Specify HTTP Cache Headers
for various page resources like for an image, so that it can be cached.
Specify/Enable compression for GZip as page-ranking mentions compression disabled in gitlab.io.
Upvotes: 9
Views: 3693
Reputation: 17177
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.
Upvotes: 7
Reputation:
If you add the precompressed .gz
versions of the files of your static site, then nginx
can serve them instead of the regular ones. Add this line to your .gitlab-ci.yml
file:
image: alpine:latest pages: stage: deploy script: - mkdir .temp - cp -r * .temp - mv .temp public - gzip -k -9 $(find public -type f) artifacts: paths: - public only: - master
This command compresses all files found in the public
directory with the maximum compression ratio.
Upvotes: 2