Simple library independent localStorage.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

JS.Simple Storage

Simple JS method to get you going with localStorage without an API. I did go ahead and add jQuery plus AngularJS aspects for my own purposes.

How it works

All I can say is why wasn't I using localStorage before... There are a couple of downsides to it. First, you can only store strings, and second how do you expire data...

This method for providing access to localStorage makes use of JSON.stringify() and JSON.parse() to handle conversion of data. In addition two date/times are applied, one for the original creation date of your data and another for when the data was updated.

Something to remember when using this, that whatever you put in you'll get back out. If you input a string you'll get a string. If you input an object, you'll get back an object. I had thought about running JSON.stringify on all stored data, but decided against it since there may have been a scenario I couldn't account for. I may go back and update the method accordingly. If you're curious about what you can jam in a JSON object view this accepted Stackoverflow answer.

Browser compatibility

Works in Firefox, Chrome, Opera, Safari, and IE9+. IE8 is technically supposed to work with storage. However IE8 and JSON.stringify get a little weird around compatibility mode. For a full list of browser compatibility regarding localStorage and JSON.stringify check Can I Use localStorage, and Can I Use, JSON.stringify


My aspect is released under the MIT License.

I did include a simple API independent "extend" method, feel free to replace with your own. I modified and pieced together my own from several answers on this Stackoverflow question.

Also I included in the demo Normalize.css and the box model tweak from Paul Irish for general formatting purposes.