From 1f345a08d5c5e03ab4e45935b427a3b62367d946 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 17 Jan 2023 14:02:34 +0100 Subject: [PATCH] Make runtimeCache compatible with middleware Nextjs Middleware will include a querystring after .json like .json?breakpoint=xs --- cache.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cache.js b/cache.js index 4f604529..179a2590 100644 --- a/cache.js +++ b/cache.js @@ -104,7 +104,17 @@ module.exports = [ } }, { - urlPattern: /\/_next\/data\/.+\/.+\.json$/i, + urlPattern: ({ url }) => { + if (self.origin !== url.origin) { + return false; + } + + if (url.pathname.startsWith('/_next/data/') && url.pathname.indexOf('.json') !== -1) { + return true; + } + + return false; + }, handler: 'StaleWhileRevalidate', options: { cacheName: 'next-data',