Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

License

Notifications You must be signed in to change notification settings

bddjr/gzipstatic-gin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gzipstatic-gin

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

Automatically use the smallest compressed file response to reduce server performance consumption.

Default encode:

gzip .gz
br .br
zstd .zst


Get

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

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":  {},
}

EncodeNameExtMap

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

EnableDebugHeader

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

Test

Dependencies: 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages