From d3b92b3d4084cfe73cf4ddbec7418653cb26558e Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Mon, 19 Jun 2023 01:05:50 +0800 Subject: [PATCH] feat: cache assets in Vercel adapter --- packages/integrations/vercel/src/edge/adapter.ts | 5 +++++ packages/integrations/vercel/src/serverless/adapter.ts | 5 +++++ packages/integrations/vercel/src/static/adapter.ts | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/integrations/vercel/src/edge/adapter.ts b/packages/integrations/vercel/src/edge/adapter.ts index 3c2d39116e95..209759adb482 100644 --- a/packages/integrations/vercel/src/edge/adapter.ts +++ b/packages/integrations/vercel/src/edge/adapter.ts @@ -151,6 +151,11 @@ export default function vercelEdge({ version: 3, routes: [ ...getRedirects(routes, _config), + { + src: '^/_astro/(.*)$', + headers: { 'cache-control': 'public, max-age=31536000, immutable' }, + continue: true, + }, { handle: 'filesystem' }, { src: '/.*', dest: 'render' }, ], diff --git a/packages/integrations/vercel/src/serverless/adapter.ts b/packages/integrations/vercel/src/serverless/adapter.ts index 8a18707702bd..19127234aff5 100644 --- a/packages/integrations/vercel/src/serverless/adapter.ts +++ b/packages/integrations/vercel/src/serverless/adapter.ts @@ -129,6 +129,11 @@ export default function vercelServerless({ version: 3, routes: [ ...getRedirects(routes, _config), + { + src: '^/_astro/(.*)$', + headers: { 'cache-control': 'public, max-age=31536000, immutable' }, + continue: true, + }, { handle: 'filesystem' }, { src: '/.*', dest: 'render' }, ], diff --git a/packages/integrations/vercel/src/static/adapter.ts b/packages/integrations/vercel/src/static/adapter.ts index f710356aa7af..15e131ad6fab 100644 --- a/packages/integrations/vercel/src/static/adapter.ts +++ b/packages/integrations/vercel/src/static/adapter.ts @@ -71,7 +71,15 @@ export default function vercelStatic({ // https://vercel.com/docs/build-output-api/v3#build-output-configuration await writeJson(new URL(`./config.json`, getVercelOutput(_config.root)), { version: 3, - routes: [...getRedirects(routes, _config), { handle: 'filesystem' }], + routes: [ + ...getRedirects(routes, _config), + { + src: '^/_astro/(.*)$', + headers: { 'cache-control': 'public, max-age=31536000, immutable' }, + continue: true, + }, + { handle: 'filesystem' }, + ], ...(imageService || imagesConfig ? { images: imagesConfig ? imagesConfig : defaultImageConfig } : {}),