Skip to content

Commit

Permalink
assets: add the correct caching headers to the prod asset server. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicks committed Feb 12, 2021
1 parent 68871fc commit 34cf0a8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/assets/prod.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ func (s prodServer) fetchFromAssetBucket(w http.ResponseWriter, req *http.Reques
// want to embed other frames.
outres.Header.Del("X-Frame-Options")

// Set caching headers according to this doc:
// https://create-react-app.dev/docs/production-build/#static-file-caching
//
// Static artifacts are checksummed and can be cached indefinitely
// The main index html page should never be cached.
if strings.HasSuffix(u.Path, "index.html") {
outres.Header.Set("Cache-Control", "no-store, max-age=0")
} else {
outres.Header.Set("Cache-Control", "public, max-age=31536000")
}

copyHeader(w.Header(), outres.Header)

resBody, err := ioutil.ReadAll(outres.Body)
Expand Down

0 comments on commit 34cf0a8

Please sign in to comment.