Skip to content

bug(service-worker): / path is omitted by ngsw-config #19945

Closed

Description

@lacolaco

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Currently, an index path, /, is omitted by ngsw-config command. It was supported as routing in old ngsw version.

$ ngsw-config ./src ./src/ngsw.base.json

ngsw.base.json

{
  "index": "src/index.html",
  "assetGroups": [
    {
      "name": "site",
      "mode": "prefetch",
      "resources": {
        "files": [
          "/",
          "/favicon.ico",
          "/index.html"
        ],
        "urls": [
          "https://fonts.googleapis.com/**"
        ],
        "versionedFiles": [
          "/*.bundle.css",
          "/*.bundle.js",
          "/*.chunk.js"
        ]
      }
    }
  ]
}

Generated ngsw.json

{
  "configVersion": 1,
  "index": "/src/index.html",
  "assetGroups": [
    {
      "name": "site",
      "installMode": "prefetch",
      "updateMode": "prefetch",
      "urls": [
        "/favicon.ico",
        "/index.html"
      ],
      "patterns": [
        "https:\\/\\/fonts\\.googleapis\\.com\\/.*"
      ]
    }
  ],
  "dataGroups": [],
  "hashTable": {
    "/favicon.ico": "84161b857f5c547e3699ddfbffc6d8d737542e01",
    "/index.html": "e5defb09b5dadd8903d71b868022bf69fc954f39"
  }
}

Expected behavior

/ should be emitted as urls to cache index.html for offline support.

{
  "configVersion": 1,
  "index": "/src/index.html",
  "assetGroups": [
    {
      "name": "site",
      "installMode": "prefetch",
      "updateMode": "prefetch",
      "urls": [
        "/", // <= should be in here
        "/favicon.ico",
        "/index.html"
      ],
      "patterns": [
        "https:\\/\\/fonts\\.googleapis\\.com\\/.*"
      ]
    }
  ],
  "dataGroups": [],
  "hashTable": {
    "/favicon.ico": "84161b857f5c547e3699ddfbffc6d8d737542e01",
    "/index.html": "e5defb09b5dadd8903d71b868022bf69fc954f39"
  }
}

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

I tried to migrate my app to new ngsw with #19795 as a referrence. But index.html is never cached.

Environment

Angular CLI: 1.5.0-rc.3
Node: 6.11.2
OS: darwin x64
Angular: 5.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

cc/ @alxhub @webmaxru

Activity

  1. webmaxru commented on Oct 26, 2017

    @webmaxru
    Member

    You don't need to add / at all. The routing is done automatically now (there is no need to specify anything for this anymore). I believe you have caching failed because of non-default base-href. Do you pass it as a 3rd parameter to ngsw CLI? In your case it should look like this: ngsw-config dist src/ngsw.base.json /src

    Offtop: @lacolaco, I'm in Tokyo Nov 13-16. My pleasure to meet you and maybe present something at ngJapan meetup!

  2. lacolaco commented on Oct 26, 2017

    @lacolaco
    ContributorAuthor

    Hmm... I changed index property from /src/index.html to /index.html, but it seems not working well.

    generated ngsw.json

    {
      "configVersion": 1,
      "index": "/index.html",
      "assetGroups": [
        {
          "name": "site",
          "installMode": "prefetch",
          "updateMode": "prefetch",
          "urls": [
            "/favicon.ico",
            "/index.html"
          ],
          "patterns": [
            "https:\\/\\/fonts\\.googleapis\\.com\\/.*"
          ]
        }
      ],
      "dataGroups": [],
      "hashTable": {
        "/favicon.ico": "84161b857f5c547e3699ddfbffc6d8d737542e01",
        "/index.html": "e5defb09b5dadd8903d71b868022bf69fc954f39"
      }
    }
    

    image

    this project is made by Angular CLI and I added ngsw files.

    image

    P.S. @webmaxru I want to see you, too! please send email to suguru.inatomi[at]gmail.com about your trip. Let's adjust our schedule :)

  3. webmaxru commented on Oct 26, 2017

    @webmaxru
    Member

    Try to upgrade to RC.6. Most likely it's the same bug as was in #19490

  4. lacolaco commented on Oct 26, 2017

    @lacolaco
    ContributorAuthor

    I already upgraded to RC.6. (see environments in 1st comment)

  5. lacolaco commented on Oct 27, 2017

    @lacolaco
    ContributorAuthor

    still happening in RC.7

  6. alxhub commented on Oct 27, 2017

    @alxhub
    Member

    Hi @lacolaco,

    Once your site loads, please open a tab and access the debugging URL /ngsw/state, and paste the contents here.

    Thanks!

  7. lacolaco commented on Oct 27, 2017

    @lacolaco
    ContributorAuthor

    @alxhub Thank you. the below is that.

    NGSW Debug Info:
    
    Driver state: NORMAL ((nominal))
    Latest manifest hash: none
    Last update check: never
    
    
    
    === Idle Task Queue ===
    Last update tick: never
    Last update run: never
    Task queue:
    
    
    Debug log:
    
    
  8. alxhub commented on Oct 28, 2017

    @alxhub
    Member

    @lacolaco please have that URL open, refresh your app, wait a few seconds and refresh the debug URL. That log indicates a service worker that has never seen a fetch.

  9. lacolaco commented on Oct 28, 2017

    @lacolaco
    ContributorAuthor

    @alxhub that's right. there is no log.

    2017-10-28 10 13 26

    The weird thing is favicon.ico is cached correctly. Why not index.html?

  10. lacolaco commented on Oct 28, 2017

    @lacolaco
    ContributorAuthor

    Ahhh, sorry, I had been enabled service worker's update on reload option. I just got actual logs

    NGSW Debug Info:
    
    Driver state: EXISTING_CLIENTS_ONLY (Degraded due to failed initialization: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting)
    Error: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting)
        at PrefetchAssetGroup.cacheBustedFetchFromNetwork (http://localhost:4200/ngsw-worker.js:657:27)
        at <anonymous>)
    Latest manifest hash: 1e8cde0a19381fa6a01acbeefefa861865f34a1f
    Last update check: 3s374u
    
    === Version 1e8cde0a19381fa6a01acbeefefa861865f34a1f ===
    
    Clients: 
    
    === Idle Task Queue ===
    Last update tick: 2s28u
    Last update run: 3s380u
    Task queue:
    
    
    Debug log:
    
    [8s401u] Error(Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting), Error: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting)
        at PrefetchAssetGroup.cacheBustedFetchFromNetwork (http://localhost:4200/ngsw-worker.js:657:27)
        at <anonymous>) initializeFully for 1e8cde0a19381fa6a01acbeefefa861865f34a1f
    
  11. lacolaco commented on Oct 29, 2017

    @lacolaco
    ContributorAuthor
  12. lacolaco commented on Nov 7, 2017

    @lacolaco
    ContributorAuthor

    At 5.0.0 stable, I finally get my offline cache!! I appreciate the team.

  13. angular-automatic-lock-bot commented on Sep 12, 2019

    @angular-automatic-lock-bot

    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.

  14. locked and limited conversation to collaborators on Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerIssues related to the @angular/service-worker package

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions