Angular 7 PWA-离线模式下缺少真棒字体图标

时间:2018-12-13 20:54:54

标签: angular font-awesome progressive-web-apps offline-caching angular-service-worker

问题在于,在离线模式下,字体真棒图标无法显示。 在离线模式下,我可以在“网络”标签中看到状态为失败的文件

  1. 在dist文件夹中生成,并且
  2. 在“应用程序”标签中的缓存中-例如/fa-solid-900.fb493903265cad425ccd.woff2

对此非常感谢。下面的详细信息-预先感谢。

阿米·科利

软件包文件中的相关条目是-

"@angular/animations": "7.1.3",
"@angular/common": "7.1.3",
"@angular/compiler": "7.1.3",
"@angular/core": "7.1.3",
"@angular/forms": "7.1.3",
"@angular/http": "7.1.3",
"@angular/platform-browser": "7.1.3",
"@angular/platform-browser-dynamic": "7.1.3",
"@angular/pwa": "^0.10.6",
"@angular/router": "7.1.3",
"@angular/service-worker": "7.1.3",
"@fortawesome/fontawesome-free": "^5.5.0",

在ngsw-config.json中-...

"/favicon.ico",
      "/index.html",
      "/*.css",
      "/*.js",
      "/*.woff",
      "/*.woff2",
      "/*.ttf",
      "/fontawesome-webfont*"
    ]

Manifest.json-

  "short_name": "TALSWeb",
  "theme_color": "#00A160",
  "background_color": "#fafafa",
  "display": "standalone",
  "scope": "/",
  "start_url": "/",

生成的ngsw.json文件摘录-

"assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "updateMode": "prefetch",
      "urls": [
        "/fa-brands-400.659c4d58b00226541ef9.woff2",
        "/fa-brands-400.8b7a9afd7b95f62e6ee8.woff",
        "/fa-brands-400.b69de69a4ff8ca0abe96.ttf",
        "/fa-regular-400.0b5e3a5451fc62d9023c.woff",
        "/fa-regular-400.b48c48ea8457846a5695.ttf",
        "/fa-regular-400.bdadb6ce95c5a2e7b673.woff2",
        "/fa-solid-900.48f54f63d7711d0912a9.ttf",
        "/fa-solid-900.bcb927a742a8370b7664.woff",
        "/fa-solid-900.fb493903265cad425ccd.woff2",
        "/favicon.ico",
        "/index.html",
        "/main.cbcf9854dbe01b31ca0f.js",
        "/polyfills.fab331e3b568bcb25c34.js",
        "/runtime.a66f828dca56eeb90e02.js",
        "/scripts.8d6556ad089996471ba5.js",
        "/styles.e844927534017e9a8be0.css"
      ],

in offline mode missing files are in the cache.PNG

3 个答案:

答案 0 :(得分:0)

在ngsw-config.json文件中,您必须在assetGroup中输入fontawesome css文件的整个CDN url /目录路径。

以便可以在第一次加载时将其缓存。

答案 1 :(得分:0)

对我来说,问题在于FA查询中存在版本号,因此导致工作箱无法缓存它,因为它认为它是另一种资源。

因此,需要设置ignoreURLParametersMatching参数,有关更多信息,请参见文档:https://developers.google.com/web/tools/workbox/modules/workbox-precaching#ignore_url_parameters

答案 2 :(得分:0)

这是我的配置:

"name": "assets",
  "installMode": "lazy",
  "updateMode": "prefetch",
  "resources": {
    "files": [
      "/assets/**",
      "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)",
      "/*-es5*.js"
    ],
    "urls": [
      "https://fonts.googleapis.com/**"
    ]
  }