A colleague at the company asked me at what point local storage should be removed from a page. As a rookie, I was questioned and told to wait for me to look at the document, but when I looked it up, ALL I found was one sentence

Clean up the strategy

The local cache is cleaned just as the code package is cleaned. The local cache is cleaned only when the code package is cleaned.

Obviously, such a sentence can not answer my doubts. So I started searching for answers from the bigwigs in the applet community, and when I did, the bigwigs were all over the place. In line with the principle of practice, I began to conduct experiments on phones with different systems. Due to my limited ability, I only tested IOS and some Android phones. This article is just a note to record the process of finding and solving problems. If there is anything wrong, I hope you can give me advice. Thank you very much.

First, I used IOS 15.3.1 and wechat 8.0.18

  • Test wechat back to the background three minutes later. (Due to time reasons, I only tested about three minutes) Result: LocalStorage is not empty
  • The test will be closed after three minutes wechat mini program. Result: LocalStorage is not cleared
  • Test after deleting wechat applets. Result: LocalStorage is not cleared
  • After the test exits the current account. Result: LocalStorage is cleared
  • Test after closing the wechat process. Result: LocalStorage is not cleared

Then I used four android phones to test mi 11, mi 8, mi 12 pro and vivo neo5 wechat version 8.0.19

  • Test wechat back to the background. Result: LocalStorage is not cleared
  • The test closes only the wechat applet process. Result: LocalStorage is not cleared
  • After the test exits the current account. Result: LocalStorage is cleared
  • Test after removing applets. Results: Mi 12 Pro was emptied and other models were not
  • Test after switching other applets after deleting applets. Results: Mi 12 Pro was cleared, Mi 11 was not cleared, and other models were not tested
  • Test only after closing the wechat process. Result: LocalStorage is not cleared

It is concluded that:

  1. The applet must clear localStorage when switching accounts.
  2. Android system: it may be because the small program and wechat are not the same process, so when the small program process is cleared, localstorage will be cleared.
  3. Android system: the difference, after the small program is deleted and deleted when switching small program Mi 12 Pro will empty localStorage.