Saidh
Saidh

Reputation: 1141

How can we include scripts into service workers?

I need to include some scripts in to my service worker. Normally we are appending scripts to DOM using document object. But in the case of service workers there is no DOM. So how can we do this using JS codes?

Thanks..

Upvotes: 1

Views: 749

Answers (2)

Dhruv Batheja
Dhruv Batheja

Reputation: 2350

Use the importScripts function. you can host your js files on an https domain and do something like this:

importScripts("//cdn.jsdelivr.net/pouchdb/5.3.1/pouchdb.min.js");

Upvotes: 2

Xzandro
Xzandro

Reputation: 977

There is a importScripts() method for that.

Upvotes: 0

Related Questions