Search code examples
firebase-hostinggoogle-cloud-run

Is it necessary to update firebase when you re-deploy a web app in cloud run, can you control what's removed from cache during re-deployment?


After deploying a web app with firebase + cloud run the firebase configurations usually don't change much.

Question 1

Is it advisable to update the cloud run container without doing a re-deployment on firebase ?

What's the advisable way to update firebase with cloud run let's say don't want to lose cache already on firebase. According to firebase a re-deployment of the web app clears all CDN cache.

Question 2

Here is my situation

I have a web app hosted on cloud run + firebase whenever I do a re-deployment I want whatever is cached from my API's from CDN not to be cleared. The rest can be cleared.

Is there a way to control what's cleared from cache during re-deployments ?

Here is my configurations

{
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [ {
      "source": "**",
      "run": {
        "serviceId": "my-site",
        "region": "some-region" 
      }
    } ],
    "headers": [{
      "source" : "**",
      "headers" : [
      {
        "key" : "Cache-Control",
        "value" : "max-age=31536000"
      }
    ]
    }]
  }
}


Solution

  • Is it advisable to update the cloud run container without doing a re-deployment on firebase ?

    Whenever you update the Cloud Run container, the changes will not be updated to the Firebase, if you want the changes to be updated to the Firebase hosting then you should consider deploying to the Firebase firebase deploy --only hosting.

    Is there a way to control what's cleared from cache during re-deployments ?

    According to the doc

    Any requested static content is automatically cached on the CDN. If you redeploy your site's content, Firebase Hosting automatically clears all your cached static content across the CDN until the next request.

    If you have dynamic content that you'll edit through an admin UI, for example. Be aware that the CDN cache will keep stale cache of that content until it expires. For example: CDN caches /blog/some-post with s-maxage of 1 day. Even if you change the content of your post dynamically, the CDN will keep the CDN for 1 full day, until it expires and it gets requested again.