Ionic app hosted on firebase requires cache clear

Issue

I have an ionic 4 app hosted on firebase and when I push an update, my users have to clear their cache to load the newest version of the app.

I’ve searched around a bit and modified my firebase.json to reflect the following:

{
  "hosting": {
    "public": "www",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "headers": [
      { "source":"/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}] }
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

I thought this worked, but today I pushed an update and it required me to clear my cache. Does anyone have other ideas on how to force an update?

Solution

Try changing this

"headers": [{"key": "Cache-Control", "value": "no-cache"}] 

to this

"headers": [{"key": "Cache-Control",  "value": "no-cache, no-store, must-revalidate"]

Or this

"headers": [{"key": "Cache-Control", "value": "public, max-age=0"}]

Also, you are setting the rule for "source" : "/service-worker.js", is that what you want?

I think you want this :

"headers": [
  {
    "source": "/**",
    "headers": [
      {
        "key": "Cache-Control",
        "value": "no-cache, no-store, must-revalidate"
      }
    ]
  }]

See what they do in this answer

This could reduce performances for the users

Answered By – BorisD

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published