From e145cbe6a0f983d3be8014205d66f3f867406545 Mon Sep 17 00:00:00 2001 From: Wim Brand Date: Mon, 18 Feb 2019 14:17:31 +0100 Subject: [PATCH] static resource caching --- webcontroller/web_controller.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webcontroller/web_controller.go b/webcontroller/web_controller.go index c90aea7..6e8c301 100644 --- a/webcontroller/web_controller.go +++ b/webcontroller/web_controller.go @@ -39,7 +39,12 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon var p = prefix // 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 r.GET(p+"/" /* */, wc.serveTemplate("home", false))