Jaslabs: High performance Software

High Performance Software

How to store large amounts of data in Firefox

by Justin Silverton

For most web applications, there are a couple of different options available for storing data on the client (within the web browser).

Flash allows the storage of up to 100 KB/domain without any user security prompts. The data being stored is accessible across the user’s Flash Player instances, loading stored data into Internet Explorer, Firefox, or any other browser that supports it.

Cookies are another option. A cookie stores user data across multiple browsing sessions. They are limited to 4 KB of storage per domain and are a good way to store user data for convenience or tracking. Web browsers contain cookie and privacy management features to wipe away stored cookies and their stored data and therefore have limited utility for continued persistence. Cookies are sent along with every request on a given domain, adding onto every message exchanged between an end-user’s browser and your site, even if the cookie data is only occasionally used.

Firefox has the ability to store an unlimited amount of data using DOM storage (This may be limited in future versions greater than 2.X).

Here is an example of how use DOM storage:

<script type="text/javascript">

//for security, this must be set to your domain
var storage = globalStorage['yourdomain.com'];
var pageCount;

function setItem(key,value) { //store an item
storage.setItem(key,value);
}

function getItem(key) { //retrieve an item and display it
alert(storage.getItem(key));
}

function removeItem(key) { //remove an item
storage.removeItem(key)
alert("Key:" +key +" was removed.");
}
</script>

Here are some other options that can be used with the globalStorage object:

  • globalStorage[’developer.mozilla.org’] - All web pages within the developer.mozilla.org sub-domain can both read and write data to this storage object.
  • globalStorage[’mozilla.org’] - All web pages with the mozilla.org domain can both read and write to this storage object.
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • DZone
  • Slashdot
  • StumbleUpon
  • Technorati

No comments yet. Be the first.

Leave a reply