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