service-worker


Can I have multiple service workers both intercept the same fetch request?


I'm writing a library which I will provide for 3rd parties to run a service worker on their site. It needs to intercept all network requests but I want to allow them to build their own service worker if they like.
Can I have both service workers intercept the same fetches and provide some kind of priority/ordering between them? Alternatively is there some other pattern I should be using?
Thanks
No, you can not. Only one service worker per scope is allowed to be registered so the latest kick the previous one out unless the scope is more specific, in this case, the request is attended by the most specific only.
Nevertheless, you can attach multiple fetch handlers and they all will process the request so maybe you can write your functionality in a separated script and let the user's service worker to include your file via importScripts().
The first handler calling event.respondWith() synchronously (actually, you can not call this method asynchronously) wins and the remaining handlers trying to call will throw.
Prioritization and coordination requires middleware. You can check ServiceWorkerWare or sw-toolbox.

Related Links

Let user choose to update Service Worker
Can I cache mp3 files using service worker?
service worker install event is called before register event is completed
Can I dynamically modify start_url in the manifest.json file?
Progressive web apps: Update sw.js on Single Page Applications
Cache hits: service workers and browsers cache [duplicate]
maxAgeSeconds in sw-toolbox not working
Activate updated service worker on refresh
service worker fetch event on first load
Using sw-toolbox with gulp
What is the purpose of service worker?
How to set BigPictureStyle on Web Push Notifications?
Best practice pattern for service worker background-sync with CSRF protection
When does code in a service worker outside of an event handler run?
Service worker JavaScript update frequency (every 24 hours?)
Can a service worker be updated thanks to a push event?

Categories

HOME
grok
search
checkstyle
deep-learning
pdfbox
edge
dojo
joomla3.0
dkim
resultset
line
speech-synthesis
flash-player
selectize.js
symbol
esoteric-languages
google-data-studio
bourbon
drive
libigl
pagespeed
epsilon
resourcebundle
stackexchange
jackson-modules
outliers
hibernate-validator
playstation-portable
android-gridview
installshield-le
jwplayer6
sql-server-ce
watchman
openalpr
metaprogramming
unordered-map
comparison-operators
dbnull
http-request
tcc
avcapturedevice
vaadin-charts
globalize
manova
static-cast
azure-cli
reshape
restore
rmongo
taocp
node-request
reporting-services-2012
ziparchive
latin
firebase-security
fuzzywuzzy
libav
jparsec
design-principles
mobiledoc-kit
asyncdisplaykit
inf
directdraw
django-urls
phonertc
pax-exam
execve
fpdi
synapse
eclipse-kepler
solace-mq
tlf
android-icons
cakephp-1.2
jdb
convention
svk
cac
resharper-6.0
uideviceorientation
vs-android
jqueryform
xpsdocument
contentpresenter

Resources

Encrypt Message