Skip to content
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

Only serve _app/immutable with immutable cache headers #5051

Merged
merged 16 commits into from
May 24, 2022
Merged

Conversation

Rich-Harris
Copy link
Member

Rather than serving everything under /_app with an immutable cache header (including /_app/version.json, which is definitely not immutable), this moves immutable assets into /_app/build so they can easily be given separate treatment.

Fixes #4837.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented May 24, 2022

🦋 Changeset detected

Latest commit: 257d2fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@sveltejs/adapter-cloudflare Patch
@sveltejs/adapter-cloudflare-workers Patch
@sveltejs/adapter-netlify Patch
@sveltejs/adapter-node Patch
@sveltejs/adapter-vercel Patch
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@bjon
Copy link
Contributor

bjon commented May 24, 2022

Previous /_app/version.json files, can already be stuck in CDNs. Maybe we can bust them with ?v2, or something?

@Rich-Harris
Copy link
Member Author

Having ?v2 in the codebase might be a bit unusual. One option for cache-busting would be to change appDir to something else (like _sveltekit or something), though not sure whether that means changing the default or just encouraging people to change it in their own apps.

It should be possible to just purge your CDN cache, though?

@bjon
Copy link
Contributor

bjon commented May 24, 2022

It should be possible to just purge your CDN cache, though?

Yes, but i was thinking about users that already downloaded the version.json.
But maybe that's not a big issue.

@Rich-Harris
Copy link
Member Author

For users it's not an issue — the request is issued with a no-cache header. It's only CDNs that don't forward no-cache requests to the origin server that are a problem, AFAICT

@bjon
Copy link
Contributor

bjon commented May 24, 2022

Yes, you're right! At least in Chrome, its works today, without a CDN.

Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

I think you'll also need to update this line:

`\n\n/${builder.config.kit.appDir}/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n`

packages/adapter-netlify/src/edge.js Show resolved Hide resolved
Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

I wonder if build is the best name for this new directory because it seems like it'll be weird to have build/_app/build. How about immutable? That would also hopefully help in keeping anyone from accidentally sticking a mutable file there

@Rich-Harris
Copy link
Member Author

Yeah, I like immutable. Will update

Copy link
Member

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

lgtm. though I mainly reviewed the netlify and node adapters since I'm most familiar with them. might be good to get eyes on the cloudflare adapters as well

@benmccann benmccann requested review from lukeed and pngwn May 24, 2022 21:32
@Rich-Harris Rich-Harris changed the title Only serve _app/build with immutable cache headers Only serve _app/immutable with immutable cache headers May 24, 2022
@Rich-Harris
Copy link
Member Author

I took another run at the cloudflare adapters and noticed a bug — now fixed

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.

/_app/version.json is marked immutable and cached forever
3 participants