自动使用最小的压缩文件响应,减少服务器性能消耗。
Automatically use the smallest compressed file response to reduce server performance consumption.
Default encode:
gzip .gz
br .br
zstd .zst
go get -u github.com/bddjr/gzipstatic-gin
// router.Static("/", "frontend/dist")
gzipstatic.Static(router, "/", "frontend/dist")// router.StaticFile("/", "frontend/dist/index.html")
gzipstatic.StaticFile(router, "/", "frontend/dist/index.html")// ctx.File("frontend/dist/index.html")
gzipstatic.File(ctx, "frontend/dist/index.html")// router.StaticFS("/", "/", fs)
gzipstatic.StaticFS(router, "/", "/", fs)// router.StaticFileFS("/", "index.html", fs)
gzipstatic.StaticFileFS(router, "/", "index.html", fs)// ctx.FileFromFS("index.html", fs)
gzipstatic.FileFromFS(ctx, "index.html", fs)gzipstatic.ExtFilterMap = map[string]struct{}{
".css": {},
".htm": {},
".html": {},
".js": {},
".json": {},
".mjs": {},
".svg": {},
".wasm": {},
".xml": {},
}gzipstatic.EncodeNameExtMap = map[string]string{
"br": ".br",
"zstd": ".zst",
"gzip": ".gz",
}// X-Encoding-By: gzipstatic-gin
gzipstatic.EnableDebugHeader = trueDependencies: Git, Go, Node.js
git clone https://github.com/bddjr/gzipstatic-gin
cd gzipstatic-gin
cd testdata
cd vite-project
npm i -g pnpm
pnpm i
pnpm build
cd ..
go build
./testdata