sw-precache icon indicating copy to clipboard operation
sw-precache copied to clipboard

cache bower components in root folder

Open simran66 opened this issue 6 years ago • 1 comments

I am using angular 1 and I have bower components in the project root.

There is app folder that has the application content.

If I register service-worker in app folder, I cannot cache bower components and then app does not work offline.

If I register service worker outside of app folder, index.html which is in app folder, is never able to find path of servie-worker.js which is outside of app folder, in the root directory.

I have tried this in index.html:

if( 'serviceWorker' in navigator ) { navigator.serviceWorker .register( '../service-worker.js' , { scope : ' ' } ) .then( function( ) { console.log('Congratulations!!Service Worker Registered'); }) .catch( function( err) { console.log(Aagh! Some kind of Error :- ${err}); }); } else { console.log("SW NOT SUPPORTED"); //still not supported } But I only get 404.

I have also tried using absolute path i.e

.register( '/service-worker.js' , { scope : ' ' } )

Also, I tried moving the folder, bower_components to inside app folder but that made no difference at all

simran66 avatar Jan 21 '18 10:01 simran66

In general, I'd recommend serving your service-worker.js from the root of your web app, and registering it via

navigator.serviceWorker.register('/service-worker.js');

I'm not sure why that wouldn't work for you—are you sure that you're properly hosting the service-worker.js file in your web app's root?

Once you get that part solved, the only question is whether sw-precache is configured properly to find the URLs for the precached files it needs to request during the service worker's installation. In order to debug that, it would be helpful if you could share your sw-precache build configuration, along with the directory listings of your local development environment, including the location of bower_components both during build time, as well as where the equivalent files are located in your web app's hosting environment.

Finally, if there are any specific errors logged in your browser's JS console related to failures to download files that should be precached, it would be great to pass those along as well.

jeffposnick avatar Jan 22 '18 17:01 jeffposnick