Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

LocalStorage and Cache clear at initial load in nextjs

In our project we need to give continuous updates, after updating the system, users need to clear their cache and localStorage data manually so that they can use the updates.

Is there any way to deal with the problem, where after updates all the cache will be cleared for once when the user comes to the site? the project is built upon Nextjs.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to have a setting which takes the version ID, compare it, if different then clear local storage and set the newer version on local storage, something like this code should work.

  var version = "v1.2";
  var storageversion = localStorage.getItem("version");
  if (storageversion !== version) {    
    localStorage.clear();
    localStorage.setItem("version", version);
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading