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:
parent
72ae013e08
commit
0d2af801ec
|
@ -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))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue