store.js
Cross-browser storage for all use cases, used across the web.
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.
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.
Where it fits
- Save user preferences or session data in the browser so they persist across page reloads without a backend.
- Use optional plugins to store data with an expiry time, so it auto-clears after a set period.
- Support a very wide range of browsers, including old Internet Explorer versions, with a single unified storage API.