Can i call a Method from an external JS File in a ServiceWorker?

那年仲夏 提交于 2020-06-03 12:30:23

问题


Is it possible to call a function from a JavaScript file out of an ServiceWorker?

Directory

root
   static
      js
         serviceworker.js

   tmpBuild
      js
         pages
            Overview.js

serviceworker.js has to call a method from Overview.js! Is that possible? And How?


回答1:


You can use importScripts() https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts

importScripts('https://example.com/script.js');


来源:https://stackoverflow.com/questions/46932176/can-i-call-a-method-from-an-external-js-file-in-a-serviceworker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!