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

feat(netlify): use new durable cache-control directive for isr rule #2571

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/presets/netlify/runtime/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function getCacheHeaders(url: string): Record<string, string> {
: "must-revalidate";
return {
"Cache-Control": "public, max-age=0, must-revalidate",
"Netlify-CDN-Cache-Control": `public, max-age=${maxAge}, ${revalidateDirective}`,
"Netlify-CDN-Cache-Control": `public, max-age=${maxAge}, ${revalidateDirective}, durable`,
};
}
return {};
Expand Down
12 changes: 7 additions & 5 deletions test/presets/netlify.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ describe("nitro:preset:netlify", async () => {
`);
});
describe("matching ISR route rule with no max-age", () => {
it("sets Netlify-CDN-Cache-Control header with revalidation after 1 year", async () => {
it("sets Netlify-CDN-Cache-Control header with revalidation after 1 year and durable directive", async () => {
const { headers } = await callHandler({ url: "/rules/isr" });
expect(
(headers as Record<string, string>)["netlify-cdn-cache-control"]
).toBe("public, max-age=31536000, must-revalidate");
).toBe("public, max-age=31536000, must-revalidate, durable");
});
it("sets Cache-Control header with immediate revalidation", async () => {
const { headers } = await callHandler({ url: "/rules/isr" });
Expand All @@ -101,11 +101,13 @@ describe("nitro:preset:netlify", async () => {
});
});
describe("matching ISR route rule with a max-age", () => {
it("sets Netlify-CDN-Cache-Control header with SWC=1yr and given max-age", async () => {
it("sets Netlify-CDN-Cache-Control header with SWC=1yr, given max-age, and durable directive", async () => {
const { headers } = await callHandler({ url: "/rules/isr-ttl" });
expect(
(headers as Record<string, string>)["netlify-cdn-cache-control"]
).toBe("public, max-age=60, stale-while-revalidate=31536000");
).toBe(
"public, max-age=60, stale-while-revalidate=31536000, durable"
);
});
it("sets Cache-Control header with immediate revalidation", async () => {
const { headers } = await callHandler({ url: "/rules/isr-ttl" });
Expand All @@ -130,7 +132,7 @@ describe("nitro:preset:netlify", async () => {
});
expect(
(headers as Record<string, string>)["netlify-cdn-cache-control"]
).toBe("public, max-age=60, stale-while-revalidate=31536000");
).toBe("public, max-age=60, stale-while-revalidate=31536000, durable");
});
}
);
Expand Down