mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-10-20 21:14:25 +02:00
admin: pre-gzip embedded static assets, add cache headers (#9918)
The admin UI served embedded static files uncompressed and without cache headers: embed.FS has zero mod times, so no Last-Modified, no ETag, no 304s -- every page load re-downloaded ~700KB of css/js in full, which gets painful over slow or tunneled links. Gzip the static tree at generation time (go generate ./weed/admin) and embed only the compressed mirror, shrinking the binary ~1.5MB. The handler hands the pre-compressed bytes to gzip-capable clients, decompresses for the rest, and sets Cache-Control, per-variant content-hash ETags and Vary so repeat loads revalidate with a 304. bootstrap.min.css goes 232KB -> 30KB on the wire. A drift test keeps static_gz/ in sync with static/.
This commit is contained in:
1 parent
c2271d59bb
commit
e56a1c4c05
24 files changed
+406
-17
No files matched your search
@@ -2,13 +2,13 @@ package admin
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
//go:embed static/*
|
||||
var StaticFS embed.FS
|
||||
//go:generate go run gen_static_gz.go
|
||||
|
||||
// GetStaticFS returns the embedded static filesystem
|
||||
func GetStaticFS() (fs.FS, error) {
|
||||
return fs.Sub(StaticFS, "static")
|
||||
}
|
||||
// staticGzFS is the gzipped mirror of static/, generated by gen_static_gz.go.
|
||||
// Only the compressed copies are embedded; StaticHandler decompresses for
|
||||
// clients that do not accept gzip.
|
||||
//
|
||||
//go:embed all:static_gz
|
||||
var staticGzFS embed.FS
|
||||
Reference in new issue
Block a user