Ryan Grove![]()
Featured ItemStorage Lite provides a lightweight YUI 3 API for persistent cross-browser local key/value storage similar to the HTML5 localStorage API. Supported browsers include IE6+, Firefox 2+, Safari 3.1+, Chrome 4+, and Opera 10.5+. No browser plugins are required (not even Flash).
Storage Lite will automatically use the best available local storage API supported by the browser it's running in. The complexities of the following storage APIs are all wrapped in a loving YUI 3 embrace and presented to you as a single consistent HTML5-like API:
When minified, Storage Lite weighs in at about 2.6KB before gzip, making it ideal for performance-critical web apps that need client-side storage capabilities across all A-grade browsers and can't depend on non-standard browser extensions.
<script src="http://yui.yahooapis.com/3.1.0/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2010.02.22-22'
}).use('gallery-storage-lite', function (Y) {
// For full compatibility with IE 6-7 and Safari 3.x, you should listen for
// the storage-lite:ready event before making storage calls. If you're not
// targeting those browsers, you can safely ignore this step.
Y.StorageLite.on('storage-lite:ready', function () {
// To store an item, pass a key and a value (both strings) to setItem().
Y.StorageLite.setItem('kittens', 'fluffy and cute');
// If you set the optional third parameter to true, you can use any
// serializable object as the value and it will automatically be stored
// as a JSON string.
Y.StorageLite.setItem('pies', ['apple', 'pumpkin', 'pecan'], true);
// To retrieve an item, pass the key to getItem().
Y.StorageLite.getItem('kittens'); // => 'fluffy and cute'
// To retrieve and automatically parse a JSON value, set the optional
// second parameter to true.
Y.StorageLite.getItem('pies', true); // => ['apple', 'pumpkin', 'pecan']
// The length() method returns a count of how many items are currently
// stored.
Y.StorageLite.length(); // => 2
// To remove a single item, pass its key to removeItem().
Y.StorageLite.removeItem('kittens');
// To remove all items in storage, call clear().
Y.StorageLite.clear();
});
});| Subject | Author | Date |
|---|---|---|
| Article introducing Storage Lite | Eric Miraglia | 02/26/10 |
| Re: Article introducing Storage Lite | Andrew Wooldridge | 03/9/10 |
© 2010 YUI Library - Site Credits