Saving Data Across Page Reloads

TLDR: sessionStorage data survives a page reload.

Probably many here already knew about this, but I was glad to find out about so I thought I’d post it.

I have a referral marketing program. If a new user comes in via a referral marketing code, the app stores the code in application state. Then if the user creates a new account, the code is saved to their new account, so people can get their referral fees. This all works as expected.

Now let’s say a new user comes in via a referral marketing code. Their code is saved to application state. Then to create their new account, this particular user reloads the page to activate their password manager. Application state is lost.

I had to find a way to save the code across page reloads.

And, sessionStorage does that. :slight_smile:

1 Like

For anybody looking at this later, here are some reference materials:

First know about web storage in general. Second the most often used ones are sessionStorage and localStorage.

Session storage is available for the duration that the page/tab remains open (including refreshes)
Local storage is more persistent and will survive even when the browser is closed and reopened. Session storage is used by default to store Meteor’s account tokens, so that users can be automatically logged in if they return to the website withing a specific time range.
@vikr00001 I would suggest to keep the referral information in localStorage for the use case when the user decides to come back at a later time to create an account.

1 Like