Question

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 :(

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top