I have a Polymer (single page app) application hosted on firebase. When I deploy a new version to firebase, I'll like firebase to reload the javascript source instead of using cached ones. Is it possible to do that via firebase.json? If so, how? Or do i have to manually add a cache busting url to my build output? Thanks
Asked
Active
Viewed 7,372 times
1 Answers
12
Adding Webpack or a similar tool to your build is probably the easiest way to go, as there's not currently a way to achieve the desired result with Firebase directly:
How Can I Make Webpack Use a Cache-Busting Suffix?
If you're okay removing the cache completely, you can simply set the related headers for the files you don't want cached in firebase.json
:
{
...
"headers": [{
"source": "build.js",
"headers": [{
"key": "Cache-Control",
"value": "max-age=0"
}]
}],
...
}
See here for more details: https://firebase.google.com/docs/hosting/full-config#headers

TMan
- 1,775
- 1
- 14
- 26
-
3but this would fetch build.js on every browser reload. I'd actually prefer if it only fetches once until the next deployment of a new version. – user3240644 Jan 19 '17 at 05:14
-
@user3240644 - That's true. I'm not sure it's possible using only `firebase.json`. Most people end up solving this via Webpack: http://stackoverflow.com/questions/39238163/how-can-i-make-webpack-use-a-cache-busting-suffix – TMan Jan 19 '17 at 21:17
-
2I would suggest removing the `firebase.json` part (or at least move it below the cache busting part) because it doesn't answer the question at all. OP explicitly mentioned "cache busting". – Franklin Yu Dec 14 '17 at 23:30
-
This answer although upvoted, doesn't actually contain an answer to the question apart from "webpack, webpack". – Ashnur Oct 28 '19 at 07:18
-
1@Ashnur - Life is richer when one turns lemons into lemonade. – TMan Oct 28 '19 at 20:11
-
@TMan no question about it, but I still don't know what the answer is for firebase. Especially since I do not wish to use webpack. – Ashnur Oct 29 '19 at 22:57