-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove cache control headers #9832
Conversation
Size Change: +3 B (0%) Total Size: 1.08 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Difficult one with the default value! I had said that we shouldn't set a max-age
but that doesn't tell us what we should set... I see why you went with public
, but on the other hand MDN tells us that:
If a request doesn't have an
Authorization
header, or you are already usings-maxage
ormust-revalidate
in the response, then you don't need to usepublic
.
which makes our intentions confusing when reading the code. My suggestion is in 2 parts:
- We should do this regardless: encapsulate the logic of what we want to do with the cache headers, so it doesn't have to be duplicated in each
getServerSideProps
- this also means we can document it better.
That probably looks like a functionsetCacheControl(res: ServerResponse): void
that lives somewhere incommon
and can just be called in eachgetServerSideProps
likesetCacheControl(context.res)
. - Then thinking about what to do in that function... I was thinking we'd have to choose a
max-age
, but your PR title gave me another idea! How about we just dores.removeHeader('Cache-Control')
- no decisions about defaults necessary! When you do this, let's add a comment explaining our reasoning (ie the fact that Next sets defaults and the fact that caching is handled in CloudFront), and let's link to the CloudFront docs and our existing cache policies
The one caveat with my suggestion (2) is if Next.js adds the header back in - we'll need to check to see whether it does that, and if it does I think, on balance, and reading the CloudFront docs, we should add a max-age
of an hour in rather than relying on default behaviours from not setting it. (I know I've changed my mind on that, sorry!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bit more detail in this comment to justify our statements, otherwise this is good!
Co-authored-by: Jamie Parkinson <j.parkinson@wellcome.ac.uk>
7fd0d2d
to
1519715
Compare
Who is this for?
Platform, by making this change to the cache-control headers, we allow users to access cached resources, instead of forcing the platform to constantly repeat the same request multiple times and taking the service down
What is it doing for them?
for now, removing all the no-cache responses, to be fine tuned at a later time, Amazon Cloudfront does have it's own cache control settings, so we will need to see what the behaviour ends up being.
note: as stated here you cannot set Cache-Control headers in the next.config file so I had to set it in all the pages files individually.