1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Use service-worker to fetch only JSON pages. (#924)

* 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.

* Use a better regexp to identify JSON pages.
This commit is contained in:
Arunoda Susiripala 2017-01-30 16:12:49 +05:30 committed by Naoyuki Kanezawa
parent 72ae013e08
commit 0d2af801ec

View file

@ -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\/[^/]+\/pages\//.test(e.request.url))) return
e.respondWith(getResponse(e.request))
})