Persists javascript objects between page requests
JavaScript CSS
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This library allows javascript objects to be saved for later use, such as between page requests or closing and opening the browser.


Copy and require lib/perseverance.js into your application.


Saving can be done by using the following:"item", myItem);

Your object can contain references to other objects, including itself, and that's ok. For instance the following should work fine:

var obj = new MyObject();
obj.someAttr = obj;"circular", obj);

There are cases however, when you may want to filter out certain elements from being saved. You may do so through a callback:"item", myItem, function(object) {
    if(typeof(object) == "object") {
        var klassName = Perseverance.getClassName(object);
        // Avoid serializing third party objects
        if(!klassName || klassName.match(/svg/i)) return false;
    return object;

Loading the object is pretty straightforward:

var myItem ="item");

Removing is as easy as:


Additional notes

The data is serialized as JSON into localStorage and rebuilt using the __proto__ attribute. It does not work in Internet Explorer. However since this attribute has been standardized in EcmaScript 6, IE11 should run ok.


This package is licensed under the MIT license and/or the Creative Commons Attribution-ShareAlike.