cacheme webp is da future

This commit is contained in:
2026-06-28 09:56:34 +03:00
parent 35191db4fb
commit ae14332c0b
3 changed files with 17 additions and 2 deletions

BIN
ABSTRACTS.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 KiB

View File

@@ -65,6 +65,6 @@
</div>
</div>
</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>
{{end}}

17
main.go
View File

@@ -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)))
}