自动使用压缩文件响应,减少服务器性能消耗。
Automatically use compressed file responses, reducing server performance consumption.
Default encode:
br .br
zstd .zst
gzip .gz
go get -u github.com/bddjr/gzipstatic-gin@latest
// 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": {},
".yaml": {},
".yml": {},
".toml": {},
}gzipstatic.EncodeNameExtMap = map[string]string{
"br": ".br",
// "zstd": ".zst",
"gzip": ".gz",
}// from high to low
gzipstatic.EncodeNamePriority = []string{
"br",
// "zstd",
"gzip",
}// X-Encoding-By: gzipstatic-gin
gzipstatic.EnableDebugHeader = true