I have recently implemented SSR with Cloud Functions and Firebase Hosting.
When the JS bundle is built it receives a cache bursting suffix (main.1.js
).
Inside my function I have the following piece of code for caching the results of the Cloud Function
res.set('Cache-Control', 'public, max-age=300, s-maxage=300');
During deploy, I deploy hosting first and then cloud function
firebase deploy --only hosting:production && gcloud functions deploy ssr --runtime nodejs8 --trigger-http --source dist/server
The firebase hosting deployment replaces main.1.js
with main.2.js
.
Due to the cache bursting the file is now different (main.2.js
) but because the cloud function is cached for another 5 minutes - I get errors when I visit the website (because main.1.js
which is referenced in the cached version of the function, is no longer available).
How would you fix such an issue? Can I have two active deployments and activate one after another?