cacheme webp is da future
This commit is contained in:
BIN
ABSTRACTS.webp
Normal file
BIN
ABSTRACTS.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 241 KiB |
@@ -65,6 +65,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
<img src="ABSTRACTS.png" style="box-shadow: 0 4px 24px rgba(0,0,0,0.6); border-radius: 6px;" />
|
<img src="ABSTRACTS.webp" style="box-shadow: 0 4px 24px rgba(0,0,0,0.6); border-radius: 6px;" />
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
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() {
|
func main() {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/ABSTRACTS.png", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/ABSTRACTS.png", func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "ABSTRACTS.png")
|
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("/src/", http.StripPrefix("/src/", http.FileServer(http.Dir("src"))))
|
||||||
mux.Handle("/content/images/", http.StripPrefix("/content/images/", http.FileServer(http.Dir("content/images"))))
|
mux.Handle("/content/images/", http.StripPrefix("/content/images/", http.FileServer(http.Dir("content/images"))))
|
||||||
|
|
||||||
@@ -49,5 +64,5 @@ func main() {
|
|||||||
mux.HandleFunc("/", blog.ServeLanding)
|
mux.HandleFunc("/", blog.ServeLanding)
|
||||||
|
|
||||||
log.Println("listening on :8000")
|
log.Println("listening on :8000")
|
||||||
http.ListenAndServe(":8000", gzipHandler(mux))
|
http.ListenAndServe(":8000", cacheHandler(gzipHandler(mux)))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user