docs icon indicating copy to clipboard operation
docs copied to clipboard

Cache responses in Cloudfront

Open dannymidnight opened this issue 2 years ago • 1 comments

Cloudfront CDN now sits between the client and our application which means we can start thinking about caching HTTP responses for a snappier user experience.

This PR does a few things to enable HTTP caching.

  • Render Login + Signup for all users regardless of them having a session. This one might be contentious! By removing the probably_authenticated check we can serve up the same cached response for all HTTP requests. A user can still access their dashboard by clicking either of those links once they're logged in.
  • Set Cache-Control headers:
    • public – this one lets Cloudfront know it's allowed to cache it
    • max-age - controls how long to cache content. I've set this to 5 minutes whilst testing.
    • must-revalidated - check origin server (our app) to see if content is still fresh using etag
  • Remove Rails CSP nonce generation 😬
    • this change removes nonce generation which was causing the Etag header to regenerate for every request - effectively preventing a page from being cached.
    • Since our CSP isn't currently being enforced this is pretty harmless but it would be nice to eventually lock down our CSP.
      • We should come back around on this once we fix up our CSP for inline-eval (see https://github.com/buildkite/docs/pull/681) .

dannymidnight avatar Apr 24 '23 05:04 dannymidnight

Your Render PR Server URL is https://bk-docs-pr-2077.onrender.com.

Follow its progress at https://dashboard.render.com/web/srv-ch31cnpmbg57g9rkt97g.

render[bot] avatar Apr 24 '23 05:04 render[bot]