============== XHTML Degrader ============== The XhtmlDegraderMiddleware class is designed to make it easier to deploy XHTML contents onto the World Wide Web. The correct MIME media type for sending XHTML is ``application/xhtml+xml`` -- the ``text/html`` media type is also acceptable provided certain guidelines_ are followed. The vast majority of web browsers released from 2002 onwards have good XHTML support; this includes the likes of Mozilla Firefox, Opera, and Apple Safari. Notable exceptions include Lynx 2.8 and Internet Explorer 7. Such browsers refuse to display XHTML, and present the user with a download dialog instead. The role of the XHTML Degrader, then, is to automatically detect when browsers do not support XHTML, and to degrade the contents into something they're capable of rendering instead. .. _guidelines: http://www.w3.org/TR/2002/REC-xhtml1-20020801/#guidelines Installation ============ Add the middleware ``'django.contrib.xhtmldegrader.middleware.XhtmlDegraderMiddleware'`` to your MIDDLEWARE_CLASSES_ setting. (If you use GZipMiddleware, you should ensure that it appears in the list before XhtmlDegraderMiddleware, to allow the XHTML Degrader to act first.) .. _MIDDLEWARE_CLASSES: ../settings/#middleware-classes How it works ============ XhtmlDegraderMiddleware checks the content type of all HTTP responses. If it's set to the XHTML media type, the ``Accept`` header (and possibly ``User-Agent`` header) are examined to determine whether the requester can in fact handle XHTML. If so, the contents is sent unaltered. If not, a number of silent changes are made to make the response more friendly for XHTML-challenged browsers and web crawlers. Firstly, the ``Content-Type`` header is set to the HTML media type. Any XML processing instructions are removed, and a ``DOCTYPE`` is added if none is present. In the case of Internet Explorer, this should ensure the content is rendered in "standards compliance" mode. Empty elements are made to have a space before their trailing slash, so for example ``
`` becomes ``
``. If an HTTP response is already set to ``text/html``, or set to any media type other than ``application/xhtml+xml``, the middleware will have no effect. Limitations =========== The XHTML Degrader does not attempt to transform content into valid HTML 4. This can be an advantage, however; for example, some XForms plug-ins for Internet Explorer 7 expect to receive XHTML sent as ``text/html``. There are differences between how CSS, DOM and scripting work within HTML, and how they behave within an XML document. One example is the case-sensitivity of CSS selectors, another would be the usage of ``document.write``. Dealing with any such issues is left to the developer.