CorvidReference

wix-storage

The wix-storage module contains functionality for the persistent storage of key/value data in the site visitor's browser.

There are three types of storage:

  • Local: Data in local storage never expires, even if the site visitor closes your page. When the visitor reopens the page later, the data can still be retrieved. You can store up to 50kb of data in local storage.

  • Session: Data in session storage is available while the site visitor's web session is active. The session ends when the visitor closes the browser tab or window. When the session ends, all the data in session storage is lost. Reloading or restoring the page does not affect session storage data. You can store up to 50kb of data in session storage.

  • Memory: Data in memory storage is available as long the site visitor does not refresh or close the page. Reloading or restoring the page clears the memory storage data. You can store up to 1mb of data in memory storage.

To use the Storage API, import the needed storage type(s) from the wix-storage module:

   import {local, session, memory} from 'wix-storage';

   // Or one of:

   import {local} from 'wix-storage';
   import {session} from 'wix-storage';
   import {memory} from 'wix-storage';

The APIs in wix-storage can only be used in front-end code.

Some older browsers may not fully support wix-storage. See Browser compatibility for more information.

Table of Contents

PROPERTIES

?
Store values associated with an object.
localUsed for local storage of data.
memoryUsed for memory storage of data.
sessionUsed for session storage of data.

Related Content

FAQ

    What's the difference between local, session, and memory storage?
    Can I use wix-storage in backend code?
    Is wix-storage data shared between site visitors?
    What kind of data can I store using wix-storage?
    How do I pass data between pages in my site?

local

Used for local storage of data.

Description

Use the methods in Storage to manage local data.

Syntax

get local(): Storage
TYPE
?
The kind of data the property stores.

Examples

Store an item in local storage

import {local} from 'wix-storage';

// ...

local.setItem("key", "value");

Retrieve an item from local storage

import {local} from 'wix-storage';

// ...

let value = local.getItem("key"); // "value"

Remove an item from local storage

import {local} from 'wix-storage';

// ...

local.removeItem("key");

Remove all items from local storage

import {local} from 'wix-storage';

// ...

local.clear();

memory

Used for memory storage of data.

Description

Use the methods in Storage to manage memory data.

Syntax

get memory(): Storage
TYPE
?
The kind of data the property stores.

Examples

Store an item in memory storage

import {memory} from 'wix-storage';

// ...

memory.setItem("key", "value");

Retrieve an item from memory storage

import {memory} from 'wix-storage';

// ...

let value = memory.getItem("key"); // "value"

Remove an item from memory storage

import {memory} from 'wix-storage';

// ...

memory.removeItem("key");

Remove all items from memory storage

import {memory} from 'wix-storage';

// ...

memory.clear();

session

Used for session storage of data.

Description

Use the methods in Storage to manage session data.

Syntax

get session(): Storage
TYPE
?
The kind of data the property stores.

Examples

Store an item in session storage

import {session} from 'wix-storage';

// ...

session.setItem("key", "value");

Retrieve an item from session storage

import {session} from 'wix-storage';

// ...

let value = session.getItem("key"); // "value"

Remove an item from session storage

import {session} from 'wix-storage';

// ...

session.removeItem("key");

Remove all items from session storage

import {session} from 'wix-storage';

// ...

session.clear();