How to import localforage to service worker using importScripts?

423 Views Asked by At

I'm trying to import localforage to my service-worker.js file. I've read, you have to use importScripts() to do so. Thing is I installed localforage in my Vue project using yarn and now i'm not sure where to access the localforage file.

I tried:

  • importScripts('localforage.js')
  • importScripts('localforage')
  • importScripts('localforage.min.js')

resulting in: service-worker.js:6 Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://webprojectname/localforage.min.js' failed to load. at https://webprojectname/service-worker.js:6:1 and: The script has an unsupported MIME type ('text/html').

I searched a lot googling but didn't find a solution. Every help is appreciated.

1

There are 1 best solutions below

2
pl4n3th On

It seems that you file is served with the wrong MIME type. Check your server config.