Skip to content

Commit

Permalink
chore(ui): add cache headers for static assets
Browse files Browse the repository at this point in the history
Signed-off-by: Remington Breeze <remington@breeze.software>
  • Loading branch information
rbreeze committed Jun 3, 2024
1 parent 5e2dac5 commit 9a9610c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func newDashboardRequestHandler() (http.HandlerFunc, error) {
}

// Path is a file
httputil.SetCacheHeaders(w, 30*24*time.Hour, 7*24*time.Hour)

Check warning on line 322 in internal/api/server.go

View check run for this annotation

Codecov / codecov/patch

internal/api/server.go#L322

Added line #L322 was not covered by tests
handler.ServeHTTP(w, req)
})

Expand Down
8 changes: 8 additions & 0 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ func SetNoCacheHeaders(w http.ResponseWriter) {
w.Header().Set(k, v)
}
}

func SetCacheHeaders(w http.ResponseWriter, maxAge time.Duration, timeUntilExpiry time.Duration) {
if w == nil {
return

Check warning on line 26 in internal/http/http.go

View check run for this annotation

Codecov / codecov/patch

internal/http/http.go#L24-L26

Added lines #L24 - L26 were not covered by tests
}
w.Header().Set("Cache-Control", "public, max-age="+maxAge.String())
w.Header().Set("Expires", time.Now().Add(timeUntilExpiry).Format(time.RFC1123))

Check warning on line 29 in internal/http/http.go

View check run for this annotation

Codecov / codecov/patch

internal/http/http.go#L28-L29

Added lines #L28 - L29 were not covered by tests
}

0 comments on commit 9a9610c

Please sign in to comment.