Set Cache-Control only when the data has been correctly fetched

This commit is contained in:
Daniele Tonon
2023-08-04 00:32:22 +02:00
parent 903bcc1712
commit ecd5d0c173
3 changed files with 9 additions and 3 deletions

View File

@@ -64,7 +64,9 @@ func renderArchive(w http.ResponseWriter, r *http.Request) {
"prevPage": fmt.Sprint(prevPage),
}
w.Header().Set("Cache-Control", "max-age=86400")
if len(data) != 0 {
w.Header().Set("Cache-Control", "max-age=86400")
}
if err := tmpl.ExecuteTemplate(w, "archive.html", params); err != nil {
log.Error().Err(err).Msg("error rendering")