Ticket #3700: xhtmldegrader.txt

File xhtmldegrader.txt, 2.7 KB (added by Dave Hodder <dmh@…>, 17 years ago)

Documentation

Line 
1==============
2XHTML Degrader
3==============
4
5The XhtmlDegraderMiddleware class is designed to make it easier to deploy XHTML
6contents onto the World Wide Web. The correct MIME media type for sending XHTML
7is ``application/xhtml+xml`` -- the ``text/html`` media type is also acceptable
8provided certain guidelines_ are followed.
9
10The vast majority of web browsers released from 2002 onwards have good XHTML
11support; this includes the likes of Mozilla Firefox, Opera, and Apple Safari.
12Notable exceptions include Lynx 2.8 and Internet Explorer 7. Such browsers
13refuse to display XHTML, and present the user with a download dialog instead.
14
15The role of the XHTML Degrader, then, is to automatically detect when browsers
16do not support XHTML, and to degrade the contents into something they're capable
17of rendering instead.
18
19.. _guidelines: http://www.w3.org/TR/2002/REC-xhtml1-20020801/#guidelines
20
21Installation
22============
23
24Add the middleware
25``'django.contrib.xhtmldegrader.middleware.XhtmlDegraderMiddleware'`` to your
26MIDDLEWARE_CLASSES_ setting. (If you use GZipMiddleware, you should ensure that
27it appears in the list before XhtmlDegraderMiddleware, to allow the XHTML
28Degrader to act first.)
29
30.. _MIDDLEWARE_CLASSES: ../settings/#middleware-classes
31
32How it works
33============
34
35XhtmlDegraderMiddleware checks the content type of all HTTP responses. If it's
36set to the XHTML media type, the ``Accept`` header (and possibly ``User-Agent``
37header) are examined to determine whether the requester can in fact handle
38XHTML. If so, the contents is sent unaltered. If not, a number of silent
39changes are made to make the response more friendly for XHTML-challenged
40browsers and web crawlers.
41
42Firstly, the ``Content-Type`` header is set to the HTML media type. Any XML
43processing instructions are removed, and a ``DOCTYPE`` is added if none is
44present. In the case of Internet Explorer, this should ensure the content is
45rendered in "standards compliance" mode. Empty elements are made to have a
46space before their trailing slash, so for example ``<br/>`` becomes ``<br />``.
47
48If an HTTP response is already set to ``text/html``, or set to any media type
49other than ``application/xhtml+xml``, the middleware will have no effect.
50
51Limitations
52===========
53
54The XHTML Degrader does not attempt to transform content into valid HTML 4.
55This can be an advantage, however; for example, some XForms plug-ins for
56Internet Explorer 7 expect to receive XHTML sent as ``text/html``.
57
58There are differences between how CSS, DOM and scripting work within HTML, and
59how they behave within an XML document. One example is the case-sensitivity of
60CSS selectors, another would be the usage of ``document.write``. Dealing with
61any such issues is left to the developer.
Back to Top