1
votes

My application served by express.js and index.html rendered by EJS Template Engine

So when i first visit my website, index.html is rendered correctly.

But if I refresh the page, index.html loaded from service worker , because

service worker's cache was the origin index.html file

I want to update some cache data (not all) or how to cache rendered html file.

For example:

enter image description here

If i want to update index.html cache data, How should I do ?

I really need someone's help.

List some angular sw configuration:

ngsw-config.json

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

My Dist project struct

/dist

--index.html

--*.js

1

1 Answers

0
votes

Ok,I find a temporary solution to solve this problem:

add data groups config to nsgw-config.json

  "dataGroups": [
    {
      "name": "api-performance",
      "urls": [
        "/api/**"(you can ignore this line),
        "/"
      ],
      "cacheConfig": {
        "strategy": "freshness",
        "maxSize": 100,
        "maxAge": "3d",
        "timeout":"2m"
      }
    }
  ]

I know we usually config this to cache json api data , But i think it also can cache html/plain text.

Although it works, but anyone has better idea?