summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2016-07-15 08:57:52 -0400
committerJoram Wilander <jwawilander@gmail.com>2016-07-15 08:57:52 -0400
commit8936f65c9032eb363ff936c6bbac5a94a348585d (patch)
tree576e14852031303d1d6715fbd64a3c2b9bca895e /web
parentb5c5744bc79d99e75629085ccafedd8f50c41916 (diff)
downloadchat-8936f65c9032eb363ff936c6bbac5a94a348585d.tar.gz
chat-8936f65c9032eb363ff936c6bbac5a94a348585d.tar.bz2
chat-8936f65c9032eb363ff936c6bbac5a94a348585d.zip
Improving caching of static assets (#3591)
Diffstat (limited to 'web')
-rw-r--r--web/web.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/web/web.go b/web/web.go
index 8e96edd69..1b50bf474 100644
--- a/web/web.go
+++ b/web/web.go
@@ -29,15 +29,22 @@ func InitWeb() {
staticDir := utils.FindDir(CLIENT_DIR)
l4g.Debug("Using client directory at %v", staticDir)
if *utils.Cfg.ServiceSettings.WebserverMode == "gzip" {
- mainrouter.PathPrefix("/static/").Handler(gziphandler.GzipHandler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))))
+ mainrouter.PathPrefix("/static/").Handler(gziphandler.GzipHandler(staticHandler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))))
} else {
- mainrouter.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))
+ mainrouter.PathPrefix("/static/").Handler(staticHandler(http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir)))))
}
mainrouter.Handle("/{anything:.*}", api.AppHandlerIndependent(root)).Methods("GET")
}
}
+func staticHandler(handler http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Cache-Control", "max-age=31556926, public")
+ handler.ServeHTTP(w, r)
+ })
+}
+
var browsersNotSupported string = "MSIE/8;MSIE/9;MSIE/10;Internet Explorer/8;Internet Explorer/9;Internet Explorer/10;Safari/7;Safari/8"
func CheckBrowserCompatability(c *api.Context, r *http.Request) bool {
@@ -68,5 +75,6 @@ func root(c *api.Context, w http.ResponseWriter, r *http.Request) {
return
}
+ w.Header().Set("Cache-Control", "no-cache, max-age=31556926, public")
http.ServeFile(w, r, utils.FindDir(CLIENT_DIR)+"root.html")
}