0

every time I make changes to my website and try to update those changes to the running website, I have to clear the cache. I saw these answers (https://stackoverflow.com/questions/51207570/how-to-clear-browser-cache-in-reactjs#:~:text=In%20your%20developer%20tools.,network%20tab%20and%20disable%20cache ) but I do not know what the best solution is

zahra zamani
  • 1,323
  • 10
  • 27

1 Answers1

2

There are a couple of things to consider, depending on what you would like to prioritize.

Want More Regular Updates? Set Cache Expiration

From the top answer of the post you linked...

for a permanent solution, you should handle this using appropriate headers sent by your API/backend

Depending on where you are serving the website from, how to configure this will change. The cache expiration is a part of the header which you should add / update to the value you would like.

Want One Immediate Update? Cache Invalidation

If you want a particular update to be pushed out ASAP to users (regardless of the last time they visited or your cache policy), invalidating the cache will force all users to fetch the latest data.

This can be done with file name versioning or host configuration options, depending on how you are hosting your website. File name versioning is also mentioned at the link you provided, as essentially requires file names to be updated with each version so that the names do not match up and force the user's browser to hard reload the data. This can also sometimes be done manually at the click of a few buttons or automatically as part of your deployment CI/CD pipeline (see AWS docs as an example)

Want Update For Development? DevTools

Also mentioned in the top answer on the post you linked, you can use the browser dev tools to clear the cache and set the option to not store a cache on your website so that you don't have to worry about it during development.

Jacob K
  • 1,096
  • 4
  • 10