I have a simple question about how Rails 3 works with XHTML doctypes. Since Rails 3 uses UJS for its ajax calls (and even normal calls such as delete calls) and does so by use of HTML5 data attributes, then, since XHTML doesn't support data attributes, will the markup be automatically invalid?
The data-*
attributes are valid in XHTML5, which is one of the encodings of HTML5. They are not valid in XHTML 1.0, but that's probably not a big problem.
Most likely, if you are serving your content to real-world browsers, they are parsing it as HTML, not XHTML. If you serve your content as text/html
, browsers will parse it as HTML. If you serve it as application/xhtml+xml
, IE 6 will render it as raw XML, not as HTML, and in other browsers, if you make one small mistake, they will stop parsing it and display an ugly error message, rather than just continuing on trying to parse the rest of the content. If you serve it as text/html
, then browsers will parse it as text/html
, so it doesn't matter whether it's valid XHTML or not.
Even if it is invalid XHTML 1.0, it is still well-formed, and web browsers are not validating user agents, so whether the content is valid or not doesn't really matter. The whole point of data-*
attributes is to provide private data to scripts on the page. As data-*
attributes don't prevent the document from being well-formed, the browser will still parse the document just fine, and your scripts will thus have access to the data, whether or not the data is valid XHTML.
The upshot is: these attributes are valid in HTML5 and XHTML5. They aren't valid in XHTML 1.0, but that doesn't really matter, as these attributes will work in all major browsers, to provide private data to the scripts on your page.