Ticket #3700: xhtmldegrader.3.txt

File xhtmldegrader.3.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 Mozilla Firefox, Opera, and Apple Safari. Two notable
12exceptions are Internet Explorer 7.0 and Netscape Navigator 4.8; instead of
13displaying XHTML, they 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 the
36XHTML media type is set, the ``Accept`` request header is examined to determine
37whether the user agent actually supports XHTML. If so, the contents is sent
38unaltered. If not, a number of silent changes are made to make the response
39more friendly to XHTML-challenged browsers and web crawlers.
40
41Firstly, the ``Content-Type`` header is set to the HTML media type. Any XML
42processing instructions are removed, and a ``DOCTYPE`` is added if none is
43present. In the case of Internet Explorer, this should ensure the content is
44rendered in "standards compliance" mode. Empty elements are made to have a
45space before their trailing slash, so for example ``<br/>`` becomes ``<br />``.
46
47If an HTTP response is already set to ``text/html``, or set to any media type
48other than ``application/xhtml+xml``, the middleware will have no effect.
49
50Limitations
51===========
52
53The XHTML Degrader does not attempt to transform content into valid HTML 4.
54This can be an advantage, however; for example, some XForms plug-ins for
55Internet Explorer 7 expect to receive XHTML sent as ``text/html``.
56
57There are differences between how CSS, DOM and scripting work within HTML, and
58how they behave within an XML document. One example is the case-sensitivity of
59CSS selectors, another would be the usage of ``document.write``. Dealing with
60any such issues is left to the developer.
Back to Top