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
{{ message }}
Repository navigation
ServiceWorker register generated by cli with base-href don't works #8515
Reacted by Marco H, Bruno Novais, Gorka Hernández Estomba, Mikhail Pavlov, Vinny Patel, Sumanth Chinthagunta, Benjamin Barbier, glemiere and Geoffrey Testelin
I'm trying to publish a PWA using github pages and always got 404 when trying to get the service-worker.
I'm using to publish it a command to automate the process- "deploy-gh-pages": "ng build --prod --base-href 'https://bikecoders.github.io/SoccerTournamentManager/' && ngh"
ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production })
Work's fine for me.
Thx @gkalpak !
Hi, It worked for me but It doesn't work in offline mode what shall I do? thanks
I have the same problem, i get HTTP error 504 when trying to access offline in Chrome (Desktop).
It works when I try Firefox, did you solve it?
Hey ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production } works fine for me too. But it doesn't work well.
I have registered my service worker and my files were added correctly
I have a base path /donde-viajar/mundo/static/. So my service worker was left:
This cause that my site does not recognized my page as a Client:
But if I open some file added into the service worker in a new tab, I get this:
So, I can't view my page in offline mode and worse than that, when I reload my page, all files added in the cache, are getting from the server, instead of the service worker.
It is not clear to me (neither from the screenshots, nor from the description) what the problem is.
If the problem persists even when using the latest versions, please post a minimal reproduction (e.g. a standalone repo) that we can use to investigate.
@gkalpak basically the service worker is registered, but it don't recognize my page, or mi index, as a cacheable. My url, that point to my index, is http://localhost:9290/donde-viajar/mundo/static?landscapes_tags=beach&distribution_type=family&experiences_tags=art,night_life&date_range_days_amount=30&date_range_month_from=8&date_range_month_to=9&locale=es-AR.
I have registered my service worker on:
When I reload the page, the index is getting from the server, instead of the service worker:
I'm not sure, if it is because i'm using routing or a base path, diferent than localhost:9290/ (in this case). I guess, because of this, none file added to the service worker, are getted from cache, instead of server.
@u-ryo I spent some hours trying to figure out the problem. And you solutions worked with different base href then "/" in that case we have to make ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }) relative. Thank you very much you are the man!
A tiny-bit unrelated but if anyone happens to find this issue when facing similar problems, here's my journey:
I too have a different base
And I do have my ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }), as the first import and with the ./ before the filename.
It still wasn't enough to even load the ngsw-worker.js file (It would've been in the logs of the http-server)
And it turned out (Thanks to this question) that Service Worker registration is broken as of angular-cli 7.3.8 and you have manually register in main.ts
Also don't forget to modify the scope and start_url in the manifest.webmanifest file
And don't forget the last forward slash. I got this message from lighthouse: start_url ("http://localhost:8080/foo") is not in the service worker's scope ("http://localhost:8080/foo/").
By the way is this a bug? I feel like it should ignore the last forward slash.
This is correct
..."scope": "/",
"start_url": "/foo/",
...
Reacted by jeffrey n. carre, Nathanael CHERRIER, Daniel B, KarlXOL, Mahdi Shiri, Jia Ji Chen, Marcellino van Hecke, rubanenko35, Bhavin Patel and Lars Rye Jeppesen
Reacted by jeffrey n. carre, Daniel B, Marvin Rohde and Bhavin Patel
angular-automatic-lock-bot commented on Sep 9, 2019
Activity
hansl commentedon Nov 22, 2017
@alxhub Could you investigate/answer this? Seems like using
--base-hrefbreaks SW.Ploppy3 commentedon Dec 19, 2017
@alxhub We need your help over here!
zmazouzi commentedon Feb 8, 2018
hello @jvitor83 can you help out,
I have the same problem, I use angular-cli 1.6.7
steps :
ng new project --service-worker
cd project
ng serve --prod
failed to load service worker to register :4200/ngsw-worker.js:-Infinity
thank you

--
gaurav2887 commentedon Feb 9, 2018
@hansl - I am also facing the same issue. Any release plan for this?
dianjuar commentedon Feb 18, 2018
Same problem with @angular/cli: 1.7.0
I'm trying to publish a PWA using github pages and always got 404 when trying to get the
service-worker.I'm using to publish it a command to automate the process-
"deploy-gh-pages": "ng build --prod --base-href 'https://bikecoders.github.io/SoccerTournamentManager/' && ngh"23 remaining items
fix(@schematics/angular): allow ServiceWorker to work with `baseHref`
fix(@schematics/angular): allow ServiceWorker to work with `baseHref`
angular/angular-cli#8515 there is a bug in the generated code that ma…
akshilshah commentedon Oct 17, 2018
Hi, It worked for me but It doesn't work in offline mode what shall I do? thanks
vallgrenerik commentedon Nov 12, 2018
valentinPeluso commentedon Nov 19, 2018
Hey






ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }works fine for me too. But it doesn't work well.I have registered my service worker and my files were added correctly
I have a base path
/donde-viajar/mundo/static/. So my service worker was left:This cause that my site does not recognized my page as a Client:
But if I open some file added into the service worker in a new tab, I get this:
So, I can't view my page in offline mode and worse than that, when I reload my page, all files added in the cache, are getting from the server, instead of the service worker.
gkalpak commentedon Nov 20, 2018
It is not clear to me (neither from the screenshots, nor from the description) what the problem is.
If the problem persists even when using the latest versions, please post a minimal reproduction (e.g. a standalone repo) that we can use to investigate.
valentinPeluso commentedon Nov 20, 2018
@gkalpak basically the service worker is registered, but it don't recognize my page, or mi index, as a cacheable. My url, that point to my index, is



http://localhost:9290/donde-viajar/mundo/static?landscapes_tags=beach&distribution_type=family&experiences_tags=art,night_life&date_range_days_amount=30&date_range_month_from=8&date_range_month_to=9&locale=es-AR.I have registered my service worker on:
When I reload the page, the index is getting from the server, instead of the service worker:
I'm not sure, if it is because i'm using routing or a base path, diferent than localhost:9290/ (in this case). I guess, because of this, none file added to the service worker, are getted from cache, instead of server.
gkalpak commentedon Nov 20, 2018
As I said before, I can't be of much help without a reproduction.
BLecha commentedon Mar 6, 2019
@u-ryo I spent some hours trying to figure out the problem. And you solutions worked with different base href then "/" in that case we have to make ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }) relative. Thank you very much you are the man!
AlexAegis commentedon Apr 24, 2019
A tiny-bit unrelated but if anyone happens to find this issue when facing similar problems, here's my journey:
I too have a different base
And I do have my
ServiceWorkerModule.register('./ngsw-worker.js', { enabled: environment.production }),as the first import and with the./before the filename.It still wasn't enough to even load the
ngsw-worker.jsfile (It would've been in the logs of thehttp-server)And it turned out (Thanks to this question) that Service Worker registration is broken as of angular-cli
7.3.8and you have manually register inmain.tsAlso don't forget to modify the
scopeandstart_urlin themanifest.webmanifestfileAnd don't forget the last forward slash. I got this message from lighthouse:
start_url ("http://localhost:8080/foo") is not in the service worker's scope ("http://localhost:8080/foo/").By the way is this a bug? I feel like it should ignore the last forward slash.
This is correct
angular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
fix(@schematics/angular): allow ServiceWorker to work with `baseHref`