URL中没有index.html的角度PWA超时

时间:2018-10-07 16:27:15

标签: angular angular-cli progressive-web-apps angular-service-worker angular-pwa

我正在使用Angular 6构建渐进式Web应用。

我已经使用Angular CLI生成了我的项目,然后使用ng add @angular/pwa添加了PWA。

我已经在Github-Pages上部署了项目。

清单和服务工作者被Google Chrome识别。我可以在主屏幕上安装我的应用,然后在线使用它。

** package.json **

{
  "name": "counterapp-pwa",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "build-gh-pages": "ng build --prod --base-href https://seza443.github.io/ng-counter-pwa/ && rm -rf docs && cp -r dist/counterapp-pwa docs",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "pwa": "ng build --prod && cd dist/counterapp-pwa && http-server -p 8080"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.1.9",
    "@angular/cdk": "^6.4.1",
    "@angular/common": "^6.1.9",
    "@angular/compiler": "^6.1.9",
    "@angular/core": "^6.1.9",
    "@angular/forms": "^6.1.9",
    "@angular/http": "^6.1.9",
    "@angular/material": "^6.4.1",
    "@angular/platform-browser": "^6.1.9",
    "@angular/platform-browser-dynamic": "^6.1.9",
    "@angular/pwa": "^0.8.4",
    "@angular/router": "^6.1.9",
    "@angular/service-worker": "^6.1.9",
    "bootstrap": "^4.1.3",
    "core-js": "^2.5.4",
    "dexie": "^2.0.4",
    "rxjs": "^6.0.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.7.0",
    "@angular/cli": "^6.2.4",
    "@angular/compiler-cli": "^6.1.9",
    "@angular/language-service": "^6.1.9",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.0",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1",
    "typescript": "~2.7.2"
  }
}

manifest.json

{
  "name": "Counter PWA",
  "short_name": "Count",
  "description": "Count stuffs",
  "theme_color": "#df10a1",
  "background_color": "#fafafa",
  "display": "standalone",
  "scope": "/",
  "start_url": "/",
  "icons": [
    {
      "src": "assets/icons/linecons_e000(0)_72.png",
      "sizes": "72x72",
      "type": "image/png"
    },
    {
      "src": "assets/icons/linecons_e000(0)_96.png",
      "sizes": "96x96",
      "type": "image/png"
    },
    {
      "src": "assets/icons/linecons_e000(0)_128.png",
      "sizes": "128x128",
      "type": "image/png"
    },
    {
      "src": "assets/icons/linecons_e000(0)_144.png",
      "sizes": "144x144",
      "type": "image/png"
    },
    {
      "src": "assets/icons/linecons_e000(0)_152.png",
      "sizes": "152x152",
      "type": "image/png"
    },
    {
      "src": "assets/icons/linecons_e000(0)_192.png",
      "sizes": "192x192",
      "type": "image/png"
    },
    {
      "src": "assets/icons/linecons_e000(0)_384.png",
      "sizes": "384x384",
      "type": "image/png"
    },
    {
      "src": "assets/icons/linecons_e000(0)_512.png",
      "sizes": "512x512",
      "type": "image/png"
    }
  ]
}

ngsw-config.json

{
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": [
          "/favicon.ico",
          "/index.html",
          "/*.css",
          "/*.js"
        ]
      }
    }, {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**"
        ]
      }
    }
  ]
}

问题是当我离线时,服务工作者无法提供页面index.html和超时:

SW timeout

但是,如果我在URL的末尾添加/index.html(仍处于脱机状态),它将正确加载页面(并从URL中删除了index.html,所以我无法再次刷新)

SW loads index.html

我在这里想念什么?感谢您的帮助。

0 个答案:

没有答案