Angular Universal with Angular Service Worker

Viewed 1748

I'm working on a project that uses SSR and SW same time.

SSR is working perfectly on first render, and when crawler reads page.

On the other hand Service Worker is working nicely too.

But problem occurs after Service Worker caches index.html file.

Here are steps that reproduces problem:

  1. When you open page first, you see that SSR rendered html and you get result instantly
  2. Then Service Worker caches everything
  3. When you refresh or change page, you don't see SSR rendered html, because index.html was cached by Service Worker
  4. If you remove index.html from caching Service Worker crashes

I'm using Angular 7.0

This is ngsw-config.json that I'm using:

{
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "updateMode": "prefetch",
      "resources": {
        "files": ["/favicon.ico", "/index.html", "/*.css", "/*.js"]
      }
    },
    {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": ["/assets/**"]
      }
    }
  ],
  "dataGroups": [
    {
      "name": "api",
      "urls": ["https://example.com/**"],
      "cacheConfig": {
        "maxSize": 30,
        "maxAge": "1d",
        "timeout": "30s",
        "strategy": "freshness"
      }
    }
  ]
}
0 Answers
Related