From 6179b81f71fdefdd62b4fec423ec4a85b78fda23 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Mon, 7 Jun 2021 11:19:10 +0200 Subject: [PATCH] no-cache for templates, tune map position --- main.go | 30 ++++++++++++++++++++++++++++++ snippets/map.html | 2 +- static/css/wo-bisch-web-custom.css | 8 ++++++-- static/js/map.js | 2 +- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index e2fb7d5..b33a0be 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,24 @@ import ( "time" ) +var epoch = time.Unix(0, 0).Format(time.RFC1123) + +var noCacheHeaders = map[string]string{ + "Expires": epoch, + "Cache-Control": "no-cache, private, max-age=0", + "Pragma": "no-cache", + "X-Accel-Expires": "0", +} + +var etagHeaders = []string{ + "ETag", + "If-Modified-Since", + "If-Match", + "If-None-Match", + "If-Range", + "If-Unmodified-Since", +} + func serveTemplate(w http.ResponseWriter, r *http.Request) { logit("Called URL: " + r.URL.Path) // wennn kein File angegeben ist: index.html @@ -77,6 +95,18 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) { // because of caching, we need to set the Last-Modified header w.Header().Set("Last-Modified", time.Now().Format(http.TimeFormat)) + // Delete any ETag headers that may have been set + for _, v := range etagHeaders { + if r.Header.Get(v) != "" { + r.Header.Del(v) + } + } + + // Set our NoCache headers + for k, v := range noCacheHeaders { + w.Header().Set(k, v) + } + if err := tmpl.ExecuteTemplate(w, "layout", &data); err != nil { logit(err.Error()) http.Error(w, http.StatusText(500), 500) diff --git a/snippets/map.html b/snippets/map.html index c5625bc..f86adc1 100644 --- a/snippets/map.html +++ b/snippets/map.html @@ -5,7 +5,7 @@ - + {{end}} {{define "body_content"}} {{ if ne .UserName "" }} diff --git a/static/css/wo-bisch-web-custom.css b/static/css/wo-bisch-web-custom.css index 5385ef2..48a5a46 100644 --- a/static/css/wo-bisch-web-custom.css +++ b/static/css/wo-bisch-web-custom.css @@ -3,7 +3,11 @@ html,body { } .section,.container { - height: 85%; + height: calc(100% - 24px); +} + +.daterangepicker { + height: 24px; } hr { @@ -80,7 +84,7 @@ input:focus, } .mapbig { - height: 100%; + height: calc(100% - 100px); } .slidecontainer { diff --git a/static/js/map.js b/static/js/map.js index 2c2f35c..7ec767c 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -135,7 +135,7 @@ function refreshDatapoints(deveui, start, stop) { $('#datetimeslider').hide(); $('#chart').html(`
- Keine Messpunkte für diese Zeitperiode + Keine GPS-Messpunkte für diese Zeitperiode
`); $('#chart').show();