开启 gzip 和 brotli
在Gemfile文件中添加:
1
2
3
4
group :jekyll_plugins do
gem 'jekyll-gzip'
gem 'jekyll-brotli'
end
然后安装插件:
1
bundle install
将插件添加到配置文件_config.yml中:
1
2
3
plugins:
- jekyll-brotli
- jekyll-gzip
构建
使用以下命令进行构建:
1
JEKYLL_ENV=production bundle exec jekyll build
这样会生成html、js、css等静态文件的br文件和gz文件。
http-server开启gzip和brotli
我使用了,在命令中添加http-server这个工具--gzip或-g开启gzip, 添加--brotli或-b开启brotli, 同时开启的话优先brotli:
1
bun run http-server /home/ubuntu/_site -p 5000 --brotli --gzip
http-server本身并不能生成gz文件和br文件,需要你在开启服务前生成好。
Static Web Server开启gzip和brotli
Static Web Server的性能更好,更轻量,而且本身有压缩功能,并不需要事先准备好压缩文件。
1
/home/ubuntu/.local/bin/static-web-server --host 127.0.0.1 --port 6000 --root ./ --directory-listing true --cors-allow-origins "*" --compression true --compression-static true
--compression-static true 这个配置项打开了静态文件压缩。