From 0cd3b12a936471a4aaa176b4c556e016111341aa Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 8 Apr 2022 16:35:39 -0500 Subject: [PATCH 1/4] docs: add assets cache-control --- docs/functions/[[path]].ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/functions/[[path]].ts b/docs/functions/[[path]].ts index 554ef48a7ac..bdaf1368668 100644 --- a/docs/functions/[[path]].ts +++ b/docs/functions/[[path]].ts @@ -14,7 +14,11 @@ export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) } if (/\.\w+$/.test(url.pathname)) { - return next(request); + const response = await req.next(req.request); + if (url.pathname.startsWith('/p-')) { + response.headers.set('Cache-Control', 'public, max-age=31536000, immutable'); + } + return response; } // do not using caching during development From 91c96dd6cfa22124dc287f752aa6ccdd981adeb1 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 8 Apr 2022 16:49:39 -0500 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=8D=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/functions/[[path]].ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/functions/[[path]].ts b/docs/functions/[[path]].ts index bdaf1368668..2d1e8053564 100644 --- a/docs/functions/[[path]].ts +++ b/docs/functions/[[path]].ts @@ -14,7 +14,7 @@ export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) } if (/\.\w+$/.test(url.pathname)) { - const response = await req.next(req.request); + const response = await req.next(request.request); if (url.pathname.startsWith('/p-')) { response.headers.set('Cache-Control', 'public, max-age=31536000, immutable'); } From f0fb8012c5633d90eb319ec0934a2b0b6efaabee Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 8 Apr 2022 16:56:59 -0500 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=8C=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/functions/[[path]].ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/functions/[[path]].ts b/docs/functions/[[path]].ts index 2d1e8053564..e5393af6093 100644 --- a/docs/functions/[[path]].ts +++ b/docs/functions/[[path]].ts @@ -14,8 +14,8 @@ export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) } if (/\.\w+$/.test(url.pathname)) { - const response = await req.next(request.request); - if (url.pathname.startsWith('/p-')) { + const response = await next(request); + if (url.pathname.startsWith('/q-')) { response.headers.set('Cache-Control', 'public, max-age=31536000, immutable'); } return response; From c1b709e2bbc6c5bd772c471b98ed1b21e8847cbc Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 15 Apr 2022 09:57:43 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8F=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/functions/[[path]].ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/functions/[[path]].ts b/docs/functions/[[path]].ts index e5393af6093..2a7424170bf 100644 --- a/docs/functions/[[path]].ts +++ b/docs/functions/[[path]].ts @@ -15,8 +15,17 @@ export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) if (/\.\w+$/.test(url.pathname)) { const response = await next(request); + if (url.pathname.startsWith('/q-')) { - response.headers.set('Cache-Control', 'public, max-age=31536000, immutable'); + // assets starting with `q-` we know can be forever cached + // current workaround until this is merged: https://github.com/cloudflare/wrangler2/pull/796 + const headers = new Headers(); + response.headers.forEach((value, key) => headers.set(key, value)); + headers.set('Cache-Control', 'public, max-age=31536000, immutable'); + return new Response([101, 204, 205, 304].includes(response.status) ? null : response.body, { + ...response, + headers, + }); } return response; } @@ -35,7 +44,7 @@ export const onRequestGet: PagesFunction = async ({ request, next, waitUntil }) // Generate Qwik SSR response const ssrResult = await render({ - url: new URL(request.url), + url: request.url, symbols, base: '/', });