SessionStroage and localStorage application scenarios

background

SessionStroage and localStorage are both HTML5 provided storage methods stored on the client side, similar to client-side databases. Storage/deletion/modification via the API features provided by H5.

In common

Both are stored in the browser and are about 5M in size, depending on the characteristics of different clients.

The difference between

  1. Validity: Seesio is deleted when the current window is closed, local persists even when the browser is closed, persistent storage
  2. Different scopes: Sessions are not shared across browser Windows, and even if the same source does not share data, local stores data that is shared across all same-origin Windows.

application

Recently, our business scenario is power station operation and maintenance. When the engineers on the station use the account, they directly open the new window

When the localstroage used for the first storage address is used, the token is likely to be washed out, resulting in user information confusion.

Change the version to session storage, which can solve the problem of user information flushing caused by incorrect login by engineers on the website, but login is required every time you open the browser (PS: data will not be stored in the client).

Talk about user information

Login storage since the way:

  1. The better it is to save cookies with the server, it will directly shuttle through HTTP requests. The disadvantage is also the same-origin policy, as mentioned above, there will be the situation of matching the number.
  2. Using localStroage feels a lot like cookies. Cookies are stored on your computer’s hard drive and will persist if you do not set an expiration date, but will disappear as time expires. LocalStroage is no way to set expiration time.
  3. When business scenarios do not consider automatic login to the web page, this is the best technical means to ensure that each page is an independent user system suitable for SPA (single page application) simple application
It is incumbent upon us to restore LPL gloryCopy the code