Manual enable browser cache (1 hour expiry) for static assets

This commit is contained in:
Alessio 2024-08-23 12:50:02 -07:00
parent 3f7a357b17
commit c16ed03f22

View File

@ -103,6 +103,8 @@ func (app *Application) ServeHTTP(w http.ResponseWriter, r *http.Request) {
parts := strings.Split(r.URL.Path, "/")[1:] parts := strings.Split(r.URL.Path, "/")[1:]
switch parts[0] { switch parts[0] {
case "static": case "static":
// Static files can be stored in browser cache
w.Header().Set("Cache-Control", "public, max-age=3600")
if use_embedded == "true" { if use_embedded == "true" {
// Serve directly from the embedded files // Serve directly from the embedded files
http.FileServer(http.FS(embedded_files)).ServeHTTP(w, r) http.FileServer(http.FS(embedded_files)).ServeHTTP(w, r)