Search code examples
cachinghtmlhtml4

Does my page have to have the HTML5 doctype to access sessionStorage


Our dev shop continues to support IE6 etc. I'm wanting to use session storage to make an app-cache but wondering how much work it would be...

Is it possible to use an HTML4 doc type in an HTML5-compatible browser and still access the sessionStorage, or do I have to browser sniff and return different pages (perhaps just with doctype alteration) to get it to work?


Solution

  • Actually, you can. Browsers don't care about doctypes. HTML 4 strict or HTML 5 won't make a difference, just make sure your page is in Standards Mode, not Quirks Mode.

    Personally, I don't see a reason not to use the HTML5 doctype, as you would be using HTML5, and, unlike any of the others, you can remember it!

    Of course, session storage as defined in HTML5 won't work in IE6—but it is up to you to decide what kind of fallback you'll provide.