[Angular] Performance Caching Policy - Cache First, Network Last


If you want to cache API response by using angular service-worker, you can do it in:

src/ngsw-config.json:

{
  "index": "/index.html",
  "assetGroups": [{
    "name": "app",
    "installMode": "prefetch",
    "resources": {
      "files": [
        "/favicon.ico",
        "/index.html"
      ],
      "versionedFiles": [
        "/*.bundle.css",
        "/*.bundle.js",
        "/*.chunk.js"
      ]
    }
  }, {
    "name": "assets",
    "installMode": "lazy",
    "updateMode": "prefetch",
    "resources": {
      "files": [
        "/assets/**"
      ]
    }
  }],
  // cache for API data
  "dataGroups": [
    {
      "name": "lessons-api",
      "urls": [
        "/api/lessons"
      ],
      "cacheConfig": {
        "strategy": "performance", // cache first, network last
        "maxAge": "1d",
        "maxSize": 100
      }
    }
  ]
}

 

智能推荐

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告