Skip to content

Conversation

@JulieGoldberg
Copy link

Added the ability to have s-maxage cache control headers when caching is public, so the length of time something is stored in a CDN can be longer than the length of time it is stored in a browser. e.g. For things stored in AWS CloudFront, https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html#ExpirationDownloadDist

Checklist

Readme.md Outdated
{
privacy: 'value',
expiresIn: 300,
serverExpiresIn: 2592000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an advanced feature and i don't think we should describe it here. Also it's incompatible with privacy: 'value'

plugin.js Outdated
value = `${_options.privacy}, max-age=${_options.expiresIn}`
}

if (_options.privacy.toLowerCase() === 'public' && _options.serverExpiresIn) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (_options.privacy.toLowerCase() === 'public' && _options.serverExpiresIn) {
if (_options.privacy !== undefined && _options.privacy.toLowerCase() === 'public' && _options.serverExpiresIn) {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Readme.md Outdated
resource may be cached. When this is set, and `privacy` is not set to `no-cache`,
then `', max-age=<value>'` will be appended to the `cache-control` header.
then `', max-age=<value>'` will be appended to the `cache-control` header. (300 seconds = 5 minutes)
+ `serverExpiresIn` (Default: `undefined`): a value, in seconds, for the *max-age* the resource may be cached on the server. When this is set, and `privacy` is set to `public`, then `', s-maxage=<value>'` will be appended to the `cache-control` header. (2,592,000 seconds = 30 days)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to prefer the explanation from MDN:

The s-maxage response directive also indicates how long the response is fresh for (similar to max-age) — but it is specific to shared caches, and they will ignore max-age when it is present.

Shared caches makes more sense as it's mostly used on CDN edges.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to integrate that without copying their language. Let me know what you think

Copy link
Member

@Fdawgs Fdawgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition!

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@JulieGoldberg JulieGoldberg requested a review from zekth November 17, 2021 19:36
Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@JulieGoldberg
Copy link
Author

Will someone with sufficient permissions merge this? I can't. It's got four approvals. Thanks!

@Eomm Eomm merged commit 865db70 into fastify:master Nov 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants