From a71090df81f9d6675a4165a5287ac8ad673fd583 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 8 Aug 2015 13:48:09 +0200 Subject: [PATCH] Enable browser caching of static resources This sends the Cache-Control header to allow caching of static resources, and checks the If-Modified-Since header to allow browser to use the cached resource on refresh. --- cmd/syncthing/gui.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 1abc189d1..559acc822 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -955,6 +955,11 @@ func (s embeddedStatic) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + if r.Header.Get("If-Modified-Since") == auto.AssetsBuildDate { + w.WriteHeader(http.StatusNotModified) + return + } + mtype := s.mimeTypeForFile(file) if len(mtype) != 0 { w.Header().Set("Content-Type", mtype) @@ -970,6 +975,7 @@ func (s embeddedStatic) ServeHTTP(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Length", fmt.Sprintf("%d", len(bs))) w.Header().Set("Last-Modified", auto.AssetsBuildDate) + w.Header().Set("Cache-Control", "public") w.Write(bs) }