reactjsfirebasecachingfirebase-hostinggtmetrix

How to Manage Cache Behavior of my React app that hosted on Firebase


I hosted my React app on Firebase and I want to optimize my site to be more user friendly. So 1st I checked the GTMetrix and it shows that there's a Medium impact to my site with Serve static assets with an efficient cache policy. When I checked firebase documentation regarding this (Manage cache behavior) I found the following line to fix it but I don't know how to do that and where I must paste the following code line. Can anyone help me with how can I do this or any external source that may be useful to do this?

res.set('Cache-Control', 'public, max-age=300, s-maxage=600');

Solution

  • I had the same issue, but after thorough R&D, i found that it should be configured on the firebase.json file (created by firebase-cli for hosting).

    Refer: https://firebase.google.com/docs/hosting/full-config#firebase-json_example

    P.S: I know i m late to this post, but hope it might help anyone looking for the same. Peace