Search code examples
requirejsofflineamdweb-workerservice-worker

RequireJS within ServiceWorker


What is the right way to use RequireJS for import external libraries within a ServiceWorker scope?

In the scope of WebWorkers we can use importScripts() RequireJS in web worker. How would be resolved in the scope of a ServiceWorker where we can be offline?.

I think that ImportScript() would fail and then need search the libraries into the Serviceworker caches, any suggestion??

Thanks a lot.

PD:I try to create the tag 'service-worker' but I dont have enough reputation ;( (I use web-worker instead).


Solution

  • I found the answer at ServiceWorker / explainer.md

    The scripts that have been imported the first time the worker is run will be cached along side it by the browser. The upside is that imported scripts will be downloaded and cached alongside the main ServiceWorker script.