3

I am trying to make my AdSense code load closer to the beginning of my mobile website code. My major bottleneck is the doctype declaration.

What I have (as shown) is the doctype mobile profile 1.2 with the following lines at the very beginning of HTML:

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

I'd like to shorten all that to:

<!DOCTYPE HTML>

But the problem is some older mobile devices might not be able to render the pages correctly. I'm trying to make my site compatible with the world.

When I use the mobile profile and when I format my HTML to make it XHTML, I score a 96% when I test my site with the W3C mobile checker at https://validator.w3.org/mobile/. However, If I do an HTML5 doctype declaration for the mobile site, W3C validator gives me between an 80 something and 94%.

I want to know if I can somehow shorten my declaration without any mobile tool complaining about document type.

I was thinking of maybe hacking the doctype so that it looks more like this:

<!DOCTYPE "XHTML Mobile 1.2" "w3.org/xhtmlmobile12.dtd"><html xmlns="w3.org/xmlns" x:lang="en">

but then again I think that's illegal.

Is there any way I can shorten this doctype so it's still XHTML-like and that it still works with as many mobile devices as possible and that it still passes doctype declatations at https://validator.w3.org/mobile/?

4

The XHTML doctype is for XHTML web pages and, unless you are serving your page as application/xhtml+xml, it ain't XHTML. I'm betting you're not doing that.

Writing HTML as XHTML is called "tag soup" and browsers will ignore what you wrote and do the best they can with it cause it won't make sense to the HTML parser. So that's a waste of time.

I've forgotten everything I knew about mobile doctypes cause I'm not sure any mobile devices acknowledge it over the last 10 years but I could be wrong and I'm going to bed in a few minutes.

The shortened doctype <!DOCTYPE html> works all the way back to IE4, believe it or not. But you can use it for XHTML documents, too.

That mobile validator appears to not have been updated since 2010. I had forgotten it even existed so I had it test one of my sites. It complained I had an invalid certificate which most certainly isn't true. So you might want to search around and see if that is a valid validator.

You may find this useful. Activating Browser Modes with Doctype

XHTML and Mobile Devices

Which mobile devices support XHTML

The conclusion I can draw from this research is that the claim that XHTML would be needed for mobile devices is simply a myth. -- Simon Peters (Opera employee and member of WHATWG)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.