Davies Tonui
Davies Tonui

Reputation: 33

Revalidating cache in React

Whenever I deploy new changes, it doesn't reflect on the user interface immediately until I clear the browser cache. It is a react front end and node back end

Upvotes: 0

Views: 668

Answers (1)

Vadim Liakhovich
Vadim Liakhovich

Reputation: 116

You will need to add versioning to your resouces (js and css) like this <script src = "filename.js?version = 1.0"></script>. You can add anything after ?, make sure it is unique each time you update your code. Browsers will cache files based on full path.

Or more common approach, you will need to use js bundler like webpack so it can generate unique hashes to your scripts and embed them in your html.

Upvotes: 1

Related Questions