zjrJS.Doc.Store.get() and .set() - zjrJS Javascript Library

This information lives on a webpage hosted at the following web address: 'https://www.omegajunior.net/code/zjrjs/'.

How to use zjrJS.Doc.Store.get() and .set().

A word from a sponsor:

zjrJS.Doc.Store.get(String key);
zjrJS.Doc.Store.set(String key, Any value);

To store data in the visitor's browser. Subsequently testing HTML5's localStorage, MS userData, and falling back to trusty old cookies.

Typical usage
Your web application needs to remember something in-between page navigation, or needs to cache often-used information form performance reasons or for off-line use. Combined with zjrJS.Doc.lS() (or an AJAX method of your choosing) to retrieve information, and a trivial check for cache expiration, zjrJS.Doc.Store may prove a tremendous help for optimizing both storage and performance.

Obligatory Privacy Talk
Since May 2011, European Law requires a web site to request explicit consent from their visitors before they set most cookies, the exception being cookies needed for services requested explicitly by that visitor. The consent requirement also covers data set using other technologies, like the localStorage employed here.

Chances are your visitors do wish to enjoy the speed and other functionality gained by allowing data to be stored on their computer.Nonetheless, you need to tell your visitors, explicitly ask for their consent, and react accordingly.

Member Type

Value Type
For .get(): String (whatever value was set, stringified automatically if needed).
For .set(): Boolean or Null. True if value was set successfully.

String key: a name of your choosing, unique to your web page's or app's URL.
Any value: anything you need to store, as long as it can be stringified.


<script type="text/javascript" src="zjrJS.version.js" id="zjrJS"></script>
<script type="text/javascript">/* <![CDATA[ */
var my=({
my.Lyric=({"one-two":"Buckle my shoe", "three-four":"Open the door"});
var S=zjrJS.Doc.Store;
S.set("motherGoose", my.Lyric);
var S=zjrJS.Doc.Store;
/* ]]> */</script>

Even though localStorage can request to store megabytes of information, understand that we fall back to cookies in case no other method is available... and browsers generally limit the amount of data a cookie can hold. So, if you need 10MB like NYTimes' Skimmer, implement your own storage routine.


Download zjrJS’ latest stable build (20141202t2322) minified (7.1KB).

Download zjrJS’ latest stable build (20141202t2322) (11.9KB).

Clicky Analytics