Detecting image requests in service workers

if (request.headers.get('Accept').includes('text/html')) {
// Handle your page requests here.
}
if (request.headers.get('Accept').includes('image')) {
// Handle your image requests here.
}
if (request.url.match(/\.(jpe?g|png|gif|svg)$/)) {
// Handle your image requests here.
}
if (request.headers.get('Accept').includes('image'))
if (request.url.match(/\.(jpe?g|png|gif|svg)$/))

--

--

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jeremy Keith

Jeremy Keith

14.2K Followers

A web developer and author living and working in Brighton, England. Everything I post on Medium is a copy — the originals are on my own website, adactio.com