Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 488
pdorgambide Avatar asked Jun 14 '26 07:06

pdorgambide


1 Answers

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.

like image 176
pdorgambide Avatar answered Jun 17 '26 22:06

pdorgambide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!