localforage vs redux-persist vs plasmo vs redux-persist-transform-encrypt
Web Storage and State Management Libraries Comparison
1 Year
localforageredux-persistplasmoredux-persist-transform-encryptSimilar Packages:
What's Web Storage and State Management Libraries?

These libraries provide various solutions for managing data in web applications, focusing on local storage, state persistence, and encryption. They help developers efficiently store and retrieve data, maintain application state across sessions, and secure sensitive information. Choosing the right library depends on the specific requirements of the application, such as the need for encryption, ease of use, or compatibility with state management frameworks like Redux.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
localforage4,405,57025,215-2484 years agoApache-2.0
redux-persist1,109,92012,993-5946 years agoMIT
plasmo89,54211,238179 kB30818 days agoMIT
redux-persist-transform-encrypt22,2853627.31 kB0a year agoMIT
Feature Comparison: localforage vs redux-persist vs plasmo vs redux-persist-transform-encrypt

Storage Mechanism

  • localforage:

    LocalForage abstracts the complexity of different storage mechanisms, allowing developers to store data using a simple API. It automatically selects the best available storage option (IndexedDB, WebSQL, or localStorage) based on browser support, providing a seamless experience for developers and users alike.

  • redux-persist:

    Redux Persist leverages localStorage or AsyncStorage (for React Native) to persist the Redux state. It serializes the Redux store and saves it, allowing the application to restore the state on reload, making it essential for applications that require state retention across sessions.

  • plasmo:

    Plasmo does not focus on storage mechanisms but rather on managing state and interactions within browser extensions. It allows developers to easily handle data flow between content scripts, background scripts, and popup interfaces, streamlining the development of complex browser extensions.

  • redux-persist-transform-encrypt:

    This package builds on Redux Persist by adding encryption capabilities. It encrypts the serialized state before saving it, ensuring that sensitive information is protected. It uses a symmetric encryption algorithm, making it suitable for applications that handle confidential data.

Ease of Use

  • localforage:

    LocalForage is designed to be user-friendly, with a simple API that resembles localStorage. It supports promises, making it easy to work with asynchronous operations, which is beneficial for developers looking for a straightforward solution to manage local data.

  • redux-persist:

    Redux Persist is relatively easy to integrate into existing Redux applications. It requires minimal configuration and provides a straightforward way to persist and rehydrate the Redux store, making it accessible for developers familiar with Redux concepts.

  • plasmo:

    Plasmo provides a high-level abstraction for building browser extensions, which simplifies the development process. It offers built-in tools and utilities that reduce boilerplate code, making it easier for developers to get started with extension development without deep knowledge of the Chrome Extension API.

  • redux-persist-transform-encrypt:

    While it adds complexity due to encryption, Redux Persist Transform Encrypt is still easy to use for developers already familiar with Redux Persist. It requires only a few additional configurations to implement encryption, making it a practical choice for those needing security.

Performance

  • localforage:

    LocalForage is optimized for performance, especially when using IndexedDB, which allows for faster read and write operations compared to traditional localStorage. Its asynchronous nature prevents blocking the main thread, ensuring smooth user experiences even with large datasets.

  • redux-persist:

    Redux Persist is efficient in persisting state, but performance can be affected by the size of the state being saved. It is essential to manage the state size and use features like whitelisting or blacklisting to optimize performance during serialization and deserialization processes.

  • plasmo:

    Plasmo is designed to optimize the performance of browser extensions by providing efficient state management and reducing unnecessary re-renders. It allows for better resource management in extensions, ensuring that they run smoothly without impacting browser performance.

  • redux-persist-transform-encrypt:

    The encryption process can introduce some overhead, potentially affecting performance. However, the impact is generally minimal compared to the security benefits it provides. Developers should balance the need for security with performance considerations, especially in applications with large states.

Security

  • localforage:

    LocalForage does not provide built-in security features, as it focuses on data storage. Developers must implement their own security measures if sensitive data is being stored, such as encrypting data before saving it to local storage.

  • redux-persist:

    Redux Persist does not offer encryption out of the box, meaning that any sensitive data stored in the Redux state could be exposed if not handled properly. Developers need to ensure that sensitive information is not stored or implement additional security measures.

  • plasmo:

    Plasmo does not inherently focus on security, but it allows developers to implement security measures in their extensions. Developers should follow best practices for securing browser extensions, such as validating user inputs and managing permissions carefully.

  • redux-persist-transform-encrypt:

    This package specifically addresses security concerns by encrypting the persisted state. It is crucial for applications that handle sensitive information, providing a layer of protection against unauthorized access to stored data.

How to Choose: localforage vs redux-persist vs plasmo vs redux-persist-transform-encrypt
  • localforage:

    Choose LocalForage if you need a simple, asynchronous storage solution that provides a consistent API across different storage backends (IndexedDB, WebSQL, and localStorage). It is ideal for applications requiring offline capabilities and supports storing complex data types like objects and arrays.

  • redux-persist:

    Opt for Redux Persist if you are using Redux for state management and want to persist your Redux store across sessions. It seamlessly integrates with Redux, allowing you to save and rehydrate the state, making it suitable for applications that require state persistence without complex configurations.

  • plasmo:

    Select Plasmo if you are building browser extensions and need a framework that simplifies the development process. Plasmo provides tools for managing state, routing, and background scripts, making it easier to create feature-rich extensions without dealing with the complexities of the Chrome Extension API directly.

  • redux-persist-transform-encrypt:

    Use Redux Persist Transform Encrypt if you need to secure the persisted state in your Redux store. This package adds encryption capabilities to Redux Persist, ensuring that sensitive data is stored securely, making it a good choice for applications handling personal or sensitive information.

README for localforage

localForage

Build Status NPM version Dependency Status npm jsDelivr Hits minzipped size

localForage is a fast and simple storage library for JavaScript. localForage improves the offline experience of your web app by using asynchronous storage (IndexedDB or WebSQL) with a simple, localStorage-like API.

localForage uses localStorage in browsers with no IndexedDB or WebSQL support. See the wiki for detailed compatibility info.

To use localForage, just drop a single JavaScript file into your page:

<script src="localforage/dist/localforage.js"></script>
<script>localforage.getItem('something', myCallback);</script>

Try the live example.

Download the latest localForage from GitHub, or install with npm:

npm install localforage

Support

Lost? Need help? Try the localForage API documentation. localForage API文档也有中文版。

If you're having trouble using the library, running the tests, or want to contribute to localForage, please look through the existing issues for your problem first before creating a new one. If you still need help, feel free to file an issue.

How to use localForage

Callbacks vs Promises

Because localForage uses async storage, it has an async API. It's otherwise exactly the same as the localStorage API.

localForage has a dual API that allows you to either use Node-style callbacks or Promises. If you are unsure which one is right for you, it's recommended to use Promises.

Here's an example of the Node-style callback form:

localforage.setItem('key', 'value', function (err) {
  // if err is non-null, we got an error
  localforage.getItem('key', function (err, value) {
    // if err is non-null, we got an error. otherwise, value is the value
  });
});

And the Promise form:

localforage.setItem('key', 'value').then(function () {
  return localforage.getItem('key');
}).then(function (value) {
  // we got our value
}).catch(function (err) {
  // we got an error
});

Or, use async/await:

try {
    const value = await localforage.getItem('somekey');
    // This code runs once the value has been loaded
    // from the offline store.
    console.log(value);
} catch (err) {
    // This code runs if there were any errors.
    console.log(err);
}

For more examples, please visit the API docs.

Storing Blobs, TypedArrays, and other JS objects

You can store any type in localForage; you aren't limited to strings like in localStorage. Even if localStorage is your storage backend, localForage automatically does JSON.parse() and JSON.stringify() when getting/setting values.

localForage supports storing all native JS objects that can be serialized to JSON, as well as ArrayBuffers, Blobs, and TypedArrays. Check the API docs for a full list of types supported by localForage.

All types are supported in every storage backend, though storage limits in localStorage make storing many large Blobs impossible.

Configuration

You can set database information with the config() method. Available options are driver, name, storeName, version, size, and description.

Example:

localforage.config({
    driver      : localforage.WEBSQL, // Force WebSQL; same as using setDriver()
    name        : 'myApp',
    version     : 1.0,
    size        : 4980736, // Size of database, in bytes. WebSQL-only for now.
    storeName   : 'keyvaluepairs', // Should be alphanumeric, with underscores.
    description : 'some description'
});

Note: you must call config() before you interact with your data. This means calling config() before using getItem(), setItem(), removeItem(), clear(), key(), keys() or length().

Multiple instances

You can create multiple instances of localForage that point to different stores using createInstance. All the configuration options used by config are supported.

var store = localforage.createInstance({
  name: "nameHere"
});

var otherStore = localforage.createInstance({
  name: "otherName"
});

// Setting the key on one of these doesn't affect the other.
store.setItem("key", "value");
otherStore.setItem("key", "value2");

RequireJS

You can use localForage with RequireJS:

define(['localforage'], function(localforage) {
    // As a callback:
    localforage.setItem('mykey', 'myvalue', console.log);

    // With a Promise:
    localforage.setItem('mykey', 'myvalue').then(console.log);
});

TypeScript

If you have the allowSyntheticDefaultImports compiler option set to true in your tsconfig.json (supported in TypeScript v1.8+), you should use:

import localForage from "localforage";

Otherwise you should use one of the following:

import * as localForage from "localforage";
// or, in case that the typescript version that you are using
// doesn't support ES6 style imports for UMD modules like localForage
import localForage = require("localforage");

Framework Support

If you use a framework listed, there's a localForage storage driver for the models in your framework so you can store data offline with localForage. We have drivers for the following frameworks:

If you have a driver you'd like listed, please open an issue to have it added to this list.

Custom Drivers

You can create your own driver if you want; see the defineDriver API docs.

There is a list of custom drivers on the wiki.

Working on localForage

You'll need node/npm and bower.

To work on localForage, you should start by forking it and installing its dependencies. Replace USERNAME with your GitHub username and run the following:

# Install bower globally if you don't have it:
npm install -g bower

# Replace USERNAME with your GitHub username:
git clone git@github.com:USERNAME/localForage.git
cd localForage
npm install
bower install

Omitting the bower dependencies will cause the tests to fail!

Running Tests

You need PhantomJS installed to run local tests. Run npm test (or, directly: grunt test). Your code must also pass the linter.

localForage is designed to run in the browser, so the tests explicitly require a browser environment. Local tests are run on a headless WebKit (using PhantomJS).

When you submit a pull request, tests will be run against all browsers that localForage supports on Travis CI using Sauce Labs.

Library Size

As of version 1.7.3 the payload added to your app is rather small. Served using gzip compression, localForage will add less than 10k to your total bundle size:

minified
`~29kB`
gzipped
`~8.8kB`
brotli'd
`~7.8kB`

License

This program is free software; it is distributed under an Apache License.


Copyright (c) 2013-2016 Mozilla (Contributors).