1

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?

0

1 Answer 1

1
+100

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

2
  • Thank you!! Took care of it! Jul 21, 2021 at 19:18
  • Can you think of any reason this would stop working? I have to go to the Firebase dashboard and manually clear the previous releases again Oct 26, 2021 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.