static resource caching

This commit is contained in:
Wim Brand
2019-02-18 14:17:31 +01:00
parent 67e6015034
commit e145cbe6a0

View File

@@ -39,7 +39,12 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
var p = prefix var p = prefix
// Serve static files // Serve static files
r.ServeFiles(p+"/res/*filepath", http.Dir(wc.staticResourceDir)) var fs = http.FileServer(http.Dir(wc.staticResourceDir))
r.GET(p+"/res/*filepath", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
w.Header().Set("Cache-Control", "public, max-age=86400") // Cache for one day
r.URL.Path = p.ByName("filepath")
fs.ServeHTTP(w, r)
})
// General navigation // General navigation
r.GET(p+"/" /* */, wc.serveTemplate("home", false)) r.GET(p+"/" /* */, wc.serveTemplate("home", false))