Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

cache bower components in root folder #343

Open
simran66 opened this issue Jan 21, 2018 · 1 comment
Open

cache bower components in root folder #343

simran66 opened this issue Jan 21, 2018 · 1 comment
Labels

Comments

@simran66
Copy link

simran66 commented Jan 21, 2018

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

@jeffposnick
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants