DockYard / ember-service-worker

A pluggable approach to Service Workers for Ember.js
http://ember-service-worker.com
MIT License
236 stars 63 forks source link

Allow customization of service worker filename #149

Closed eshtadc closed 5 years ago

eshtadc commented 5 years ago

From https://github.com/DockYard/ember-service-worker/pull/81 Submitted by @jniechcial

Motivation

I am using ember-service-worker with OneSignal Push Notifications. Their SDK provides you service worker with following code:

self.importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');

And they claim that it's filename (OneSignalSDKWorker.js) is required for their SDK to work.

Solution

I solved it by using the output service worker from ember-service-worker as an importScript in the OneSignalSDK worker:

self.importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');
self.importScripts('sw.js');

However, sw-registration.js is always pointing to sw.js. This PR adds possibility to define which service worker should be registered while still producing the output to sw.js.

I still wonder if it's best possible solution or maybe there is some other way that I didn't think about. What do you think?

PS. I feel that my naming (serviceWorkerFileName) is rather confusing and should be changed before merge. Looking forward to your proposition if you agree we should move forward with it.