8

I'm keen to test out html offline storage and caching with a view to developing a prototype to show off the offline web application capabilities of html5.

I've found some webkit-specific samples, but I'm battling to find any decent code samples that even work at all in Firefox 3.6

For a sample, I'd be happy with something that works with the following:

  • Our company uses jquery extensively so I'd prefer samples that use that library or pure javascript.
  • It should at least work on firefox (3.6+ is fine)

Can anyone point me to some links that provide some guidance and code samples?

5 Answers 5

3

See http://hacks.mozilla.org/?s=localStorage

Firefox doesn't support SQL database API, if that's what you're looking for.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - there's some good stuff there and also in the post comments.
3

I found this example, it is the simplest / best thing I have seen with localstorage. It only demonstrates the local (persistent) storage, not database storage. Also, if you want session storage, just change "localStorage" to sessionStorage"

The javascript couldn't be any simpler I think.

w3.org example

And yes, it works fine with FF (at least for me.)

Comments

1

I recommend looking at the CSS Ninja's Font Dragr demonstration which, although primarily designed to demonstrate the File API for HTML5 using Firefox, also makes use of Offline Storage.

If nothing else, this guy knows his stuff and can suggest good examples.

Comments

1

I've found this pretty good page of html5 demos recently so thought I'd post it back here.

html5demos.com

Edit - another link that may help:

From the Google Chrome development team comes HTML5rocks, a site to feature and educate webmasters on the awesome new features of HTML5.

www.html5rocks.com

Edit #2 - this is one of the best articles I've come across yet:

wrapping things nicely with html5 local storage

Comments

0

Knowing offline storage is supported by all the major browsers now, I put up a jQuery plugin for handling form state. http://www.jasonsebring.com/dumbFormState and the source is small and easy to understand.

I recommend the approach to do serialization using Douglas Crockford's JSON2.stringify : https://github.com/douglascrockford/JSON-js to take an object in JavaScript and turn it into a JSON string. Then you can save that to either window.sessionStorage or window.localStorage easily like so:

// setting data

window.sessionStorage['mydata'] = JSON.stringify(someObject);

// getting it back

someObject = jQuery.parseJSON(window.sessionStorage['mydata']);

Another thing to think about is namespacing your keys. For what I was doing, I wanted it automatic so key names were saved based off 'dumbFormState-' + window.location.pathname + '-' + form index to ensure the keys were automatically unique then you could loop through them later do delete them by checking the prefix 'dumbFormState-' matching they keys as you don't want to delete any other stuff on there that people may use.

Hope that helps a bit.

2 Comments

a minor comment, for the newer browsers, crockfords api of JSON2.stringify is not recommended. This API is now supported natively in the browses
good point, but the script uses native if supported. -> stackoverflow.com/questions/1480393/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.