[Answered] wix-storage -> session / storage explantion

Hello. I need some explanation on the functionality of the ‘session’ storage. in my site code I have put the following pieces of code.

import {session} from 'wix-storage';
...
session.clear(); 
...
session.setItem("item", "value");
...

What I expect is that when the site is reloaded the session information is first cleared out and then set again. However this doesn’t seem to be the case exactly. With refresh I mean e.g. F5. Forcing refresh, CTRL+F5, works better.

Did I mis implement something?

Edit: So I’m changing this a wee bit. I have this session storage working, but Now I added a ‘button’ on the header. I made a click event as follows.

export function toggleDutch(event, $w) {
	console.log("go");
	console.log(session.getItem("vttLangauge"));
	session.setItem("vttLanguage", "nl");
		console.log(session.getItem("vttLangauge"));
	wixLocation.to("/overview-list");
}

I would expect the two first console outputs, but strangely the second is not displayed when I do the preview. I would like to know why this would be the case. If in the ‘site code’ ‘onReady’ I fill in the session with fallback to value ‘en’ it shouldn’t be empty. In fact if I load a page data is collected correctly.

Can someone advice? I’m for now going to try and see what happens with local storage instead.

EDIT: Workaround local storage is working perfectly. Also the advantage is the info is stored for next time. I’ll try to add a check later on for local storage usage. So the local storage is a small database in the browsers. Session info is gone when the browser closes (read more here). My experience though is that this session info sometimes doesn’t do what you think (a general experience, not only Wix). So I switched to local storage. In chrome developer tools I saw by just changing ‘session’ to ‘local’ everything started working like I expected.

1 Like