angular / mobile-toolkit

Tools for building progressive web apps with Angular
MIT License
1.34k stars 175 forks source link

Add support for --base-href #143

Open marcalj opened 7 years ago

marcalj commented 7 years ago

I'm using --base-href /n-angular4/ to build but it doesn't generate the correct paths in the ngsw-manifest.json file in dist folder.

ngsw-manifest.json

{
    "routing": {
        "index": "/index.html",
        "routes": {
            "/": {
                "prefix": false
            }
        }
    }
}

After manually setting the new paths and clearing the Service Worker it's finally working.

marcalj commented 7 years ago

Note that it should be registered with a scope: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register

navigator.serviceWorker.register('/sw-test/sw.js', {scope: '/n-angular4/'})

NOTE: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers

marcalj commented 7 years ago

In Chrome Canary I'm getting this error:

Console: {"lineNumber":0,"message":"The FetchEvent for \"https://love.com/n-angular4/#!/auth/login\" resulted in a network error response: the promise was rejected.","message_level":2,"sourceIdentifier":1,"sourceURL":""}
Console: {"lineNumber":0,"message":"Uncaught (in promise) TypeError: Failed to fetch","message_level":3,"sourceIdentifier":1,"sourceURL":"https://love.com/n-angular4/worker-basic.min.js"}
marcalj commented 7 years ago

I'm totally lost, I've been able to make it work in Chrome, but with a new version, when going offline it doesn't work now :/

marcalj commented 7 years ago

In Firefox it seems that file ngsw-manifest.json is not cached (is not declared in static.urls and Firefox shows an corrupted error warning when offline because it cannot load it.

webmaxru commented 7 years ago

Firefox has some strange behaviour for respondWith() method. Could you confirm the Failed to load .... A ServiceWorker passed a redirected Response to FetchEvent.respondWith() while RedirectMode is not ‘follow’. error in DevTools?

webmaxru commented 7 years ago

This change should fix Corrupted Content Error in Firefox: https://github.com/GoogleChrome/sw-precache/pull/233/files - it was only the beginning of the discussion. The actual fix is: https://github.com/GoogleChrome/sw-precache/pull/241

More context: https://github.com/GoogleChrome/sw-precache/issues/220 Technical background: https://bugs.chromium.org/p/chromium/issues/detail?id=669363&desc=2#c1

@alxhub, please have a look

marcalj commented 7 years ago

In Chrome Canary I can inspect the first fetch:

sw

image