[英]How to enable GZip compression for Gitlab Pages?
When using Gitlab Pages to render my site which is slow in page-ranking.当使用Gitlab Pages呈现我的网站时,页面排名很慢。 I can't find any solution on how to do following in GitLab ( non-enterprise version )我在 GitLab(非企业版)中找不到关于如何执行以下操作的任何解决方案
Specify HTTP Cache Headers
for various page resources like for an image, so that it can be cached.为各种页面资源(如图像)指定HTTP Cache Headers
,以便可以缓存它。
Specify/Enable compression for GZip as page-ranking mentions compression disabled in gitlab.io.指定/启用 GZip 压缩,因为页面排名提到在 gitlab.io 中禁用压缩。
You can compress contents of your public folder via .gitlab-ci.yml :您可以通过.gitlab-ci.yml压缩公共文件夹的内容:
script:脚本:
GitLab has support for serving compressed assets if you pre-compress them in the pages
CI Job already.如果您已经在pages
CI 作业中预先压缩了压缩资产,GitLab 支持提供压缩资产。 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.请注意,您可以并且也应该使用brotli
压缩,因为它针对 Web 内容进行了优化,并得到了大多数现代浏览器的支持。
There is also a suggested snippet for your .gitlab-ci.yml
:您的.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.我也在找这个。
If you add the precompressed .gz
versions of the files of your static site, then nginx
can serve them instead of the regular ones.如果您添加静态站点文件的预压缩.gz
版本,则nginx
可以提供它们而不是常规文件。 Add this line to your .gitlab-ci.yml
file:将此行添加到您的.gitlab-ci.yml
文件中:
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.此命令以最大压缩率压缩在public
目录中找到的所有文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.