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
When run the build script with the inline argument of --base-href /current/ and in the ngsw.json file use the absolute path for the files, it produces the path /current/index.html in the built ngsw.json. Using of the relative path in the ngsw.json does not help.
Expected behavior
Either using the relative path in the ngsw.json or generating the output due to the --base-href value.
Environment
Angular version: 5.0.0
@angular/service-worker: 5.2.10
Browser:
- [x] Chrome (desktop) version 65
For Tooling issues:
- Node version: 8.9.4
- Platform: Windows
Yeah, I've been thinking about this one myself (if I understand correctly what you are saying).
I would expect that baseHref would only be prepended to relative paths, not absolute paths.
Oh...wait. Actually, these are file paths (not urls). So, you can't really know whether the urls will be relative or absolute. Asset-group urls are treated correctly (only prepending baseHref to relative urls).
It might be a useful feature though, to be able to indicate whether a file requires baseHref to be prepended or not.
But in the config ngsw.json you only absolute paths work. Whern I use the relative path ./index.html, the output is /baseHref/index.html. And it breaks the structure.
For future reference:
The ngsw.json manifest includes some paths to files in the project's output directory. For example, assetGroups -> <group-name> -> resources -> files or index. It is not clear what effect --baseHref should have on those.
On one hand, it might seem reasonable to prepend the base href to relative paths (e.g. foo/file) and leave absolute paths (e.g. /foo/file) alone.
On the other hand, these are file paths (not URLs) and they are interpreted with the project's output directory as root, so both relative and absolute paths refer to the same files.
Changing the behavior of --baseHref to only affect relative paths might give people an option to use either behavior (i.e. they could use relative paths if they want them to be prepended with the base href and absolute paths otherwise), but that would (a) be a breaking change and (b) lead to unexpected/hard-to-debug changes in behavior from seemingly innocent change.
We should look into how we can accomodate all usecases with as predictable a behavior as possible (and document these things in detail).
Note that the CLI, in addition to --baseHref also has a --deployUrl option, but it is not clear what its behavior is and whether its use is encouraged (e.g. I know there have been discussions about removing it).
Activity
gkalpak commentedon Apr 18, 2018
Yeah, I've been thinking about this one myself (if I understand correctly what you are saying).
I would expect that
baseHrefwould only be prepended to relative paths, not absolute paths.E.g.:
Expected (with
baseHref = /foo/):Actual (with
baseHref = /foo/):cc @alxhub
gkalpak commentedon Apr 18, 2018
Oh...wait. Actually, these are file paths (not urls). So, you can't really know whether the urls will be relative or absolute. Asset-group
urlsare treated correctly (only prependingbaseHrefto relative urls).It might be a useful feature though, to be able to indicate whether a file requires
baseHrefto be prepended or not.zizizi17 commentedon Apr 18, 2018
But in the config
ngsw.jsonyou only absolute paths work. Whern I use the relative path./index.html, the output is/baseHref/index.html. And it breaks the structure.gkalpak commentedon May 25, 2020
For future reference:
The
ngsw.jsonmanifest includes some paths to files in the project's output directory. For example,assetGroups -> <group-name> -> resources -> filesorindex. It is not clear what effect--baseHrefshould have on those.foo/file) and leave absolute paths (e.g./foo/file) alone.Changing the behavior of
--baseHrefto only affect relative paths might give people an option to use either behavior (i.e. they could use relative paths if they want them to be prepended with the base href and absolute paths otherwise), but that would (a) be a breaking change and (b) lead to unexpected/hard-to-debug changes in behavior from seemingly innocent change.We should look into how we can accomodate all usecases with as predictable a behavior as possible (and document these things in detail).
Note that the CLI, in addition to
--baseHrefalso has a--deployUrloption, but it is not clear what its behavior is and whether its use is encouraged (e.g. I know there have been discussions about removing it).JeanMeche commentedon Aug 29, 2025
With #63364 we've announced that the service-worker package in now in maintenance mode and will not receive feature PRs and feature requests.
The message is also visible here: https://angular.dev/ecosystem/service-workers
angular-automatic-lock-bot commentedon Sep 29, 2025
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.