Skip to content

Commit

Permalink
Use service-worker to fetch only JSON pages. (vercel#924)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
arunoda authored and nkzawa committed Jan 30, 2017
1 parent 72ae013 commit 0d2af80
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions client/next-prefetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down

0 comments on commit 0d2af80

Please sign in to comment.