You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using create-react-app and I'm trying to modify an auto-generated service worker so that it imports workbox from a local file instead of from a cdn. I don't want to eject or use react-app-rewired or similar solutions since they seem likely to break in the future.
With this tool, I've been able to append the required code at the bottom of the file, but is it possible to replace importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js"); with the appended code so that workbox is only imported locally? If that is not possible, is it possible to keep the precache-manifest import auto-generated and hard code the rest? The precache-manifest import is the only thing that I need to auto-generate because it changes over time.
Thank you!
My service worker:
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/
// to be replaced
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
// I want to keep this auto-generated
importScripts(
"/precache-manifest.d88aedb260a4fc1dbfabddc4949f8bef.js"
);
self.addEventListener('message', (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting();
}
});
workbox.core.clientsClaim();
/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("/index.html"), {
blacklist: [/^\/_/,/\/[^/?]+\.[^/]+$/],
});
// appended code
importScripts('/workbox/workbox-v5.1.3/workbox-sw.js');
workbox.setConfig({
modulePathPrefix: '/workbox/workbox-v5.1.3/'
});'
});
The text was updated successfully, but these errors were encountered:
Hi!
I'm using create-react-app and I'm trying to modify an auto-generated service worker so that it imports workbox from a local file instead of from a cdn. I don't want to eject or use react-app-rewired or similar solutions since they seem likely to break in the future.
With this tool, I've been able to append the required code at the bottom of the file, but is it possible to replace
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
with the appended code so that workbox is only imported locally? If that is not possible, is it possible to keep theprecache-manifest
import auto-generated and hard code the rest? The precache-manifest import is the only thing that I need to auto-generate because it changes over time.Thank you!
My service worker:
The text was updated successfully, but these errors were encountered: