views:

645

answers:

2

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?

A: 

Good question... theoretically the answer is no, but practically it's vendor dependent. My solution would be to have the server check the user-agent and dynamically tag the page accordingly to what you find out when testing cross-browser implementation. Unfortunately this is one of those things you can't do dynamically on the client (change doc type) as you would with Javascript implementation fixes.

Robert Gould
No, the answer is not vendor-dependent. It’s not even theoretically no. (There’s nothing in the sessionStorage spec suggesting that support be disabled based on doctype.) The answer: sessionStorage doesn’t depend on the doctype in any way.
hsivonen
+2  A: 

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.

Ms2ger
Also see http://stackoverflow.com/questions/5629/any-reason-not-to-start-using-the-html-5-doctype
Stephen