From 5812175a3e81d1919fe6ec5a90e3b5dcfbee22b3 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Mon, 30 Jan 2017 09:14:34 +0530 Subject: [PATCH 1/2] Use service-worker to fetch only JSON pages. We simply don't need to proxy other requests through that. That's might cause some latency issues. --- client/next-prefetcher.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/next-prefetcher.js b/client/next-prefetcher.js index 83101837f99bd..b5418cd360efb 100644 --- a/client/next-prefetcher.js +++ b/client/next-prefetcher.js @@ -16,12 +16,8 @@ self.addEventListener('activate', (e) => { }) self.addEventListener('fetch', (e) => { - const h = e.request.headers - const accept = h.getAll ? h.getAll('accept') : h.get('accept').split(',') - for (const a of accept) { - // bypass Server Sent Events - if (a === 'text/event-stream') return - } + // bypass all requests except JSON pages. + if (!(/_next\/[\w-]*\/pages/.test(e.request.url))) return e.respondWith(getResponse(e.request)) }) From 6570427acae2da71da055168f2333409cedf0c14 Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Mon, 30 Jan 2017 15:18:44 +0530 Subject: [PATCH 2/2] Use a better regexp to identify JSON pages. --- client/next-prefetcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/next-prefetcher.js b/client/next-prefetcher.js index b5418cd360efb..32a747cb85943 100644 --- a/client/next-prefetcher.js +++ b/client/next-prefetcher.js @@ -17,7 +17,7 @@ self.addEventListener('activate', (e) => { self.addEventListener('fetch', (e) => { // bypass all requests except JSON pages. - if (!(/_next\/[\w-]*\/pages/.test(e.request.url))) return + if (!(/\/_next\/[^/]+\/pages\//.test(e.request.url))) return e.respondWith(getResponse(e.request)) })