我可以从 ServiceWorker 中的外部 JS 文件调用方法吗? [英] Can i call a Method from an external JS File in a ServiceWorker?

查看:45
本文介绍了我可以从 ServiceWorker 中的外部 JS 文件调用方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从 ServiceWorker 中调用 JavaScript 文件中的函数?

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

目录

root
   static
      js
         serviceworker.js

   tmpBuild
      js
         pages
            Overview.js

serviceworker.js 必须调用 Overview.js 中的方法!那可能吗?怎么做?

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

推荐答案

你可以使用 importScripts() https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts

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

这篇关于我可以从 ServiceWorker 中的外部 JS 文件调用方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆