diff options
author | Alan Pearce | 2024-05-31 06:03:52 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-31 06:03:52 +0200 |
commit | 896926a63a8f2d145467b325f9b0198315e0af6d (patch) | |
tree | dd298424bc99f87bb4c1c96d8be753908801eeb9 /internal | |
parent | 66b2556a6a7c911a69b231fddeefe0a939d8898d (diff) | |
download | searchix-896926a63a8f2d145467b325f9b0198315e0af6d.tar.lz searchix-896926a63a8f2d145467b325f9b0198315e0af6d.tar.zst searchix-896926a63a8f2d145467b325f9b0198315e0af6d.zip |
feat: serve assets via immutable paths
Diffstat (limited to 'internal')
-rw-r--r-- | internal/server/mux.go | 13 |
1 files changed, 10 insertions, 3 deletions
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 { |