explaingit

marcuswestin/store.js

13,994JavaScriptAudience · developerComplexity · 1/5Setup · easy

TLDR

Store.js is a JavaScript library that gives websites a simple, consistent way to save and retrieve small pieces of data in the user's browser across page loads, hiding the messy differences between browser storage APIs.

Mindmap

mindmap
  root((store.js))
    What It Does
      Browser data storage
      Cross-browser compat
      Simple unified API
    Core Actions
      Set and get values
      Remove and clear
      Loop over all data
    Features
      Plugin system
      Expiring data
      Change notifications
    Builds
      Legacy all browsers
      Modern smaller build
      npm or script tag
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Save user preferences or session data in the browser so they persist across page reloads without a backend.

USE CASE 2

Use optional plugins to store data with an expiry time, so it auto-clears after a set period.

USE CASE 3

Support a very wide range of browsers, including old Internet Explorer versions, with a single unified storage API.

Tech stack

JavaScriptnpmlocalStoragesessionStorage

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Store.js is a small JavaScript library that lets a website save little pieces of data inside a person's own web browser, so the site can remember things between page loads or visits. Browsers offer a few different ways to do this, and they do not all behave the same, especially older ones. Store.js hides those differences behind one simple set of commands that works the same way everywhere. The README notes it has existed since 2010 and is used on tens of thousands of sites, naming cnn.com and dailymotion.com as examples. The core of the library is a handful of basic actions. You can set a value under a name, get it back later, remove it, clear everything, or loop over all the saved values. The README shows short code samples, for instance saving a user's details under the name user and reading them back. You add the library to a project either through the npm package manager or by including one of its prebuilt files with a script tag in a web page. Store.js is built to support a very wide range of browsers, and the README lists tested versions going back to old releases of Internet Explorer as well as mobile browsers and Node. To balance file size against compatibility, it ships in several builds: a legacy build that supports everything, a smaller modern build, a version with all extras included, and one for compatibility with the library's first version. Beyond the basics, the README describes optional plugins that add features such as default values, expiring stored data after a set time, and getting notified when a value changes. You can also write your own plugin. Underneath, the data is kept in one of several storage methods, like localStorage, sessionStorage, or cookies, and store.js automatically picks the best one available and falls back to another if the first does not work.

Copy-paste prompts

Prompt 1
Using store.js, write JavaScript that saves a user's dark mode preference in the browser and reads it back on page load.
Prompt 2
How do I use the store.js expiry plugin to save a JWT token that automatically clears after 24 hours?
Prompt 3
Show me how to use store.js to store a shopping cart array in the browser and update it when the user adds or removes items.
Prompt 4
How do I use the store.js events plugin to listen for when a stored value changes and update the UI automatically?
Open on GitHub → Explain another repo

← marcuswestin on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.