1

我正在使用 Angular 6 构建一个渐进式 Web 应用程序。

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

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

Manifest 和 Service-Worker 被 Google Chrome 识别。我可以在主屏幕上安装我的应用程序并在线使用它。

** 包.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"
  }
}

清单.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/**"
        ]
      }
    }
  ]
}

问题是当我离线时,Service-Worker 不提供页面index.html和超时:

软件超时

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

SW 加载 index.html

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

4

0 回答 0