Skip to content

bddjr/gzipstatic-gin

Repository files navigation

gzipstatic-gin

自动使用压缩文件响应,减少服务器性能消耗。

Automatically use compressed file responses, reducing server performance consumption.

Default encode:

br .br
zstd .zst
gzip .gz


Get

go get -u github.com/bddjr/gzipstatic-gin@latest

Example

Static

// router.Static("/", "frontend/dist")
gzipstatic.Static(router, "/", "frontend/dist")

StaticFile

// router.StaticFile("/", "frontend/dist/index.html")
gzipstatic.StaticFile(router, "/", "frontend/dist/index.html")

File

// ctx.File("frontend/dist/index.html")
gzipstatic.File(ctx, "frontend/dist/index.html")

StaticFS

// router.StaticFS("/", "/", fs)
gzipstatic.StaticFS(router, "/", "/", fs)

StaticFileFS

// router.StaticFileFS("/", "index.html", fs)
gzipstatic.StaticFileFS(router, "/", "index.html", fs)

FileFromFS

// ctx.FileFromFS("index.html", fs)
gzipstatic.FileFromFS(ctx, "index.html", fs)

ExtFilterMap

gzipstatic.ExtFilterMap = map[string]struct{}{
	".css":  {},
	".htm":  {},
	".html": {},
	".js":   {},
	".json": {},
	".mjs":  {},
	".svg":  {},
	".wasm": {},
	".xml":  {},
	".yaml": {},
	".yml":  {},
	".toml": {},
}

EncodeNameExtMap

gzipstatic.EncodeNameExtMap = map[string]string{
	"br":   ".br",
	// "zstd": ".zst",
	"gzip": ".gz",
}

EncodeNamePriority

// from high to low
gzipstatic.EncodeNamePriority = []string{
	"br",
	// "zstd",
	"gzip",
}

EnableDebugHeader

// X-Encoding-By: gzipstatic-gin
gzipstatic.EnableDebugHeader = true

About

📦自动使用最小的压缩文件响应,减少服务器性能消耗。Automatically use the smallest compressed file response to reduce server performance consumption.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages