cacheme webp is da future
This commit is contained in:
17
main.go
17
main.go
@@ -33,11 +33,26 @@ func gzipHandler(next http.Handler) http.Handler {
|
||||
})
|
||||
}
|
||||
|
||||
func cacheHandler(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.URL.Path, "/src/") ||
|
||||
strings.HasPrefix(r.URL.Path, "/content/images/") ||
|
||||
strings.HasPrefix(r.URL.Path, "/ABSTRACTS.") ||
|
||||
strings.HasPrefix(r.URL.Path, "/blog/og/") {
|
||||
w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
|
||||
}
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/ABSTRACTS.png", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "ABSTRACTS.png")
|
||||
})
|
||||
mux.HandleFunc("/ABSTRACTS.webp", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, "ABSTRACTS.webp")
|
||||
})
|
||||
mux.Handle("/src/", http.StripPrefix("/src/", http.FileServer(http.Dir("src"))))
|
||||
mux.Handle("/content/images/", http.StripPrefix("/content/images/", http.FileServer(http.Dir("content/images"))))
|
||||
|
||||
@@ -49,5 +64,5 @@ func main() {
|
||||
mux.HandleFunc("/", blog.ServeLanding)
|
||||
|
||||
log.Println("listening on :8000")
|
||||
http.ListenAndServe(":8000", gzipHandler(mux))
|
||||
http.ListenAndServe(":8000", cacheHandler(gzipHandler(mux)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user