The concept seems simple, but implementation logic seems daunting right now.
I use localStorage in my app, and I want to clear it when I update the code.
Any ideas how?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could store the code version in the script and compare that when you load the script:
If you don’t want to track the version manually, you can generate the “version” by hashing the script. A good hash is a balance between ease of implementation (this kinda rules out MD5, unless you’re willing to fetch a library), hash size (you don’t want to store a copy of the script in localStorage) and its detection capabilities (so the string length may not suffice).
Needless to say, deleting all storage with any single change may be too cautious, so I recommend the manual version tracking approach, or (better yet) refactor the application so that it can work with the previous version data.