Skip to content

Commit

Permalink
feat(netlify): use new durable cache-control directive for isr ru…
Browse files Browse the repository at this point in the history
…le (#2571)
  • Loading branch information
serhalp authored Jun 28, 2024
1 parent 6408c5c commit 8693087
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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

0 comments on commit 8693087

Please sign in to comment.