From 495b524d3481a9b6cb53d3d0cf4032e0f3b6fcab Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Wed, 20 Sep 2023 18:28:10 +0200 Subject: [PATCH 1/3] set cache busting header to deck asset links --- prow/cmd/deck/main.go | 12 ++++-------- prow/cmd/deck/template/base.html | 12 ++++++------ prow/cmd/deck/template/command-help.html | 4 ++-- prow/cmd/deck/template/index.html | 2 +- prow/cmd/deck/template/job-history.html | 2 +- prow/cmd/deck/template/plugins.html | 6 +++--- prow/cmd/deck/template/pr.html | 6 +++--- prow/cmd/deck/template/spyglass.html | 6 +++--- prow/cmd/deck/template/tide-history.html | 2 +- prow/cmd/deck/template/tide.html | 4 ++-- 10 files changed, 26 insertions(+), 30 deletions(-) diff --git a/prow/cmd/deck/main.go b/prow/cmd/deck/main.go index d7f48ce6ed43..5f3f771ace35 100644 --- a/prow/cmd/deck/main.go +++ b/prow/cmd/deck/main.go @@ -731,14 +731,10 @@ func loadToken(file string) ([]byte, error) { func handleCached(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // This looks ridiculous but actually no-cache means "revalidate" and - // "max-age=0" just means there is no time in which it can skip - // revalidation. We also need to set must-revalidate because no-cache - // doesn't imply must-revalidate when using the back button - // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1 - // TODO: consider setting a longer max-age - // setting it this way means the content is always revalidated - w.Header().Set("Cache-Control", "public, max-age=0, no-cache, must-revalidate") + // Since all static assets have a cache busting parameter + // attached, which forces a reload whenever Deck is updated, + // we can send strong cache headers. + w.Header().Set("Cache-Control", "public, max-age=315360000") // 315360000 is 10 years, i.e. forever next.ServeHTTP(w, r) }) } diff --git a/prow/cmd/deck/template/base.html b/prow/cmd/deck/template/base.html index 10e4388ea46b..8492d72a94e9 100644 --- a/prow/cmd/deck/template/base.html +++ b/prow/cmd/deck/template/base.html @@ -26,16 +26,16 @@ {{end}} {{block "title" .Arguments}}Prow{{ end }} - - - + + + - + {{block "scripts" .Arguments}}{{end}} -{{$defaultLogo := "/static/logo-light.png"}} +{{ $defaultLogo := "/static/logo-light.png" }} {{- if .DarkMode -}} {{- $defaultLogo = "/static/logo-dark.png" -}} {{- end -}} @@ -45,7 +45,7 @@
+ class="logo"> {{block "pageTitle" .Arguments}}{{template "title" .}}{{end}}
diff --git a/prow/cmd/deck/template/command-help.html b/prow/cmd/deck/template/command-help.html index 7a948280f61b..6ebd807c7e40 100644 --- a/prow/cmd/deck/template/command-help.html +++ b/prow/cmd/deck/template/command-help.html @@ -1,7 +1,7 @@ {{define "title"}}Command Help{{end}} {{define "scripts"}} - - + + {{end}} {{define "content"}} diff --git a/prow/cmd/deck/template/index.html b/prow/cmd/deck/template/index.html index 7eb333f01fc0..d69ddd1ac0a4 100644 --- a/prow/cmd/deck/template/index.html +++ b/prow/cmd/deck/template/index.html @@ -1,7 +1,7 @@ {{define "title"}}Prow Status{{end}} {{define "scripts"}} - + + diff --git a/prow/cmd/deck/template/plugins.html b/prow/cmd/deck/template/plugins.html index f3c1c7b29877..5d5e5a66cfff 100644 --- a/prow/cmd/deck/template/plugins.html +++ b/prow/cmd/deck/template/plugins.html @@ -1,9 +1,9 @@ {{define "title"}}Prow Plugin Catalog{{end}} {{define "scripts"}} - - - + + + {{end}} diff --git a/prow/cmd/deck/template/pr.html b/prow/cmd/deck/template/pr.html index b8cd257faef3..549d0f9102aa 100644 --- a/prow/cmd/deck/template/pr.html +++ b/prow/cmd/deck/template/pr.html @@ -1,8 +1,8 @@ {{define "title"}}PR Status{{end}} {{define "scripts"}} - - - + + + {{end}} diff --git a/prow/cmd/deck/template/spyglass.html b/prow/cmd/deck/template/spyglass.html index 5c595efe0a92..7909812b12f2 100644 --- a/prow/cmd/deck/template/spyglass.html +++ b/prow/cmd/deck/template/spyglass.html @@ -10,8 +10,8 @@ var prowJobName = {{.ProwJobName}}; var prowJobState = {{.ProwJobState}}; - - + + {{end}} {{define "content"}} @@ -42,7 +42,7 @@

{{$config.Title}}

- loading spinner + loading spinner
diff --git a/prow/cmd/deck/template/tide-history.html b/prow/cmd/deck/template/tide-history.html index 1867115dfe38..745ac097f61f 100644 --- a/prow/cmd/deck/template/tide-history.html +++ b/prow/cmd/deck/template/tide-history.html @@ -1,7 +1,7 @@ {{define "title"}}Tide History{{end}} {{define "scripts"}} - + {{end}} diff --git a/prow/cmd/deck/template/tide.html b/prow/cmd/deck/template/tide.html index 46c167ad9797..cac9c6cc1e1a 100644 --- a/prow/cmd/deck/template/tide.html +++ b/prow/cmd/deck/template/tide.html @@ -1,8 +1,8 @@ {{define "title"}}Tide Status{{end}} {{define "scripts"}} - - + + {{end}} From 0f6185b81f67cdf2d55a3fabba85772b5d280b1d Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Wed, 20 Sep 2023 18:28:43 +0200 Subject: [PATCH 2/3] remove deprecated Pragma header --- prow/cmd/deck/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/prow/cmd/deck/main.go b/prow/cmd/deck/main.go index 5f3f771ace35..ca016088afcf 100644 --- a/prow/cmd/deck/main.go +++ b/prow/cmd/deck/main.go @@ -745,7 +745,6 @@ func setHeadersNoCaching(w http.ResponseWriter) { // IE "no-store". for good measure to cover older browsers we also set // expires and pragma: https://stackoverflow.com/a/2068407 w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") - w.Header().Set("Pragma", "no-cache") w.Header().Set("Expires", "0") } From 2f40dd05ea75a552377de6e8512babbb13167816 Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Wed, 20 Sep 2023 18:33:18 +0200 Subject: [PATCH 3/3] remove IE 6.0 compatibility --- prow/cmd/deck/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/prow/cmd/deck/main.go b/prow/cmd/deck/main.go index ca016088afcf..ad6f5d75198f 100644 --- a/prow/cmd/deck/main.go +++ b/prow/cmd/deck/main.go @@ -740,11 +740,10 @@ func handleCached(next http.Handler) http.Handler { } func setHeadersNoCaching(w http.ResponseWriter) { - // Note that we need to set both no-cache and no-store because only some - // browsers decided to (incorrectly) treat no-cache as "never store" - // IE "no-store". for good measure to cover older browsers we also set - // expires and pragma: https://stackoverflow.com/a/2068407 - w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate") + // This follows the "ignore IE6, but allow prehistoric HTTP/1.0-only proxies" + // recommendation from https://stackoverflow.com/a/2068407 to prevent clients + // from caching the HTTP response. + w.Header().Set("Cache-Control", "no-store, must-revalidate") w.Header().Set("Expires", "0") }