mirror of
https://github.com/aljazceru/njump.git
synced 2025-12-18 06:44:22 +01:00
Set Cache-Control only when the data has been correctly fetched
This commit is contained in:
@@ -317,7 +317,9 @@ func render(w http.ResponseWriter, r *http.Request) {
|
||||
templateMapping[typ] = "other.html"
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "max-age=604800")
|
||||
if (strings.Contains(typ, "profile") && len(renderableLastNotes) != 0) || (!strings.Contains(typ, "profile") && len(content) != 0) {
|
||||
w.Header().Set("Cache-Control", "max-age=604800")
|
||||
}
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, templateMapping[typ], params); err != nil {
|
||||
log.Error().Err(err).Msg("error rendering")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -72,7 +72,9 @@ func renderRelayPage(w http.ResponseWriter, r *http.Request) {
|
||||
"modifiedAt": lastEventAt.Format("2006-01-02T15:04:05Z07:00"),
|
||||
}
|
||||
|
||||
w.Header().Set("Cache-Control", "max-age=604800")
|
||||
if len(renderableLastNotes) != 0 {
|
||||
w.Header().Set("Cache-Control", "max-age=604800")
|
||||
}
|
||||
|
||||
if err := tmpl.ExecuteTemplate(w, templateMapping[typ], params); err != nil {
|
||||
log.Error().Err(err).Msg("error rendering")
|
||||
|
||||
Reference in New Issue
Block a user