magneticow: web: enable caching static resources for 24 hours

This commit is contained in:
Bora Alper 2018-08-27 20:25:41 +03:00
parent 74ca0cac13
commit 2328087edb

View File

@ -30,7 +30,9 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
// TODO: we might as well move torrents.html into static...
func torrentsHandler(w http.ResponseWriter, r *http.Request) {
data := mustAsset("templates/torrents.html")
w.Header().Set("Content-Type", http.DetectContentType(data))
w.Header().Set("Content-Type", "text/html; charset=utf-8")
// Cache static resources for a day
w.Header().Set("Cache-Control", "max-age=86400")
w.Write(data)
}
@ -75,7 +77,9 @@ func torrentsInfohashHandler(w http.ResponseWriter, r *http.Request) {
// TODO: we might as well move statistics.html into static...
func statisticsHandler(w http.ResponseWriter, r *http.Request) {
data := mustAsset("templates/statistics.html")
w.Header().Set("Content-Type", http.DetectContentType(data))
w.Header().Set("Content-Type", "text/html; charset=utf-8")
// Cache static resources for a day
w.Header().Set("Cache-Control", "max-age=86400")
w.Write(data)
}
@ -149,5 +153,7 @@ func staticHandler(w http.ResponseWriter, r *http.Request) {
contentType = http.DetectContentType(data)
}
w.Header().Set("Content-Type", contentType)
// Cache static resources for a day
w.Header().Set("Cache-Control", "max-age=86400")
w.Write(data)
}