views:

108

answers:

1

Is there any difference in <noscript> block processing for pages served with MIME-type text/html versus those served with MIME-type application/xhtml+xml?

As far as I noticed <noscript> block for text/html pages is not processed at all if JavaScript is disabled in browser. And what happens for application/xhtml+xml pages? I suspect that for such pages the block is still analysed when JavaScript is disabled. But I failed to find any clarification of this issue.

Could someone point me to appropriate W3C standard or provide any other clarification?

PS. Situation of interest is visit counting services wich use <noscript> block to track visitors with disabled JS. If elements (for example, zero-sized images) of <noscript> blocks are downloaded in any case then such services should broke :(

A: 

The best description is probably the one in the HTML5 draft here : http://dev.w3.org/html5/spec/semantics.html#the-noscript-element.

In text/html, the details of exactly what happens are quite complex. Just follow the link above. No point in reproducing here.

For application/xhtml+xml, the draft says:

The noscript element must not be used in XML documents.

The noscript element is only effective in the HTML syntax, it has no effect in the XHTML syntax.

So in application/xhtml+xml, the contents of noscript should be displayed regardless of whether scripting is available or not. Of course, if scripting is enabled, it's pretty trivial to use script to remove such elements from the DOM.

CORRECTION.

On further research, what the above quote means I think, is that the noscript element has no effect on the parsing.

In the XHTML section here, http://dev.w3.org/html5/spec/the-xhtml-syntax.html#the-xhtml-syntax, the draft says

The user agent is expected to hide noscript elements for whom scripting is enabled, irrespective of CSS rules.

So, as you say, when scripting is enabled the noscript element does hide its contents. However, that's all it does, and images are loaded anyway. In addition, I tried this:

<html xml:lang="en-GB" xmlns="http://www.w3.org/1999/xhtml" lang="en-GB">
  <head> 
    <title>Test</title>
  </head>
  <body>
    <p>Test 1</p>
    <noscript id="ns">
      <p>Test 2</p>
      <script type="text/javascript">
        document.getElementById("ns").parentNode.removeChild(document.getElementById("ns"));
      </script>
      <img src="test.gif" alt="test"/>
    </noscript>
  </body>
</html>

And although the noscript node is removed from the dom, Firefox still tried to load the image.

Alohci
I'm not using HTML5 doctype but XHTML 1.1. I guess, it makes difference, doesn't it? Please, correct me if I'm wrong.I've experimented a bit and can claim that in application/xhtml+xml the contents of noscript are NOT displayed if JS is disabled, but are still loaded (there is a corresponding http request/response). Does all modern browsers don't follow standards when dealing with xml documents?If I remove noscript (or its contents) from the DOM (when JS is enabled) will its contents still be loaded before they are removed?
kurniliya
The doctype makes no difference at all. But see my correction above.
Alohci
Thanks for your answer with a quick and handy example. To add up a bit, I've found the following at http://wiki.whatwg.org/wiki/HTML_vs._XHTML (actually, it states the same as your answer but with no any prooflink): "In HTML, if scripting is enabled, the noscript element is parsed as an CDATA element. If scripting is disabled, it's parsed as a normal element. In XHTML, the element is always parsed as a normal element<..>"
kurniliya