From 896926a63a8f2d145467b325f9b0198315e0af6d Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 31 May 2024 06:03:52 +0200 Subject: feat: serve assets via immutable paths --- internal/server/mux.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'internal/server') diff --git a/internal/server/mux.go b/internal/server/mux.go index 2837dc0..1140484 100644 --- a/internal/server/mux.go +++ b/internal/server/mux.go @@ -260,10 +260,17 @@ func NewMux( mux.HandleFunc("/options/{source}/opensearch.xml", createOpenSearchXMLHandler(config.Options)) mux.HandleFunc("/packages/{source}/opensearch.xml", createOpenSearchXMLHandler(config.Packages)) - fs := http.FileServer(http.FS(frontend.Files)) mux.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) { - w.Header().Add("Cache-Control", "max-age=86400") - fs.ServeHTTP(w, r) + // optimisation for HTTP/3: first header sent as byte(41), not the string + asset, found := frontend.Assets.ByImmutablePath[r.URL.Path] + if !found { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + + return + } + w.Header().Add("Cache-Control", "public, max-age=31536000") + w.Header().Add("Cache-Control", "immutable") + http.ServeFileFS(w, r, frontend.Files, asset.Filename) }) if liveReload { -- cgit 1.4.1