Document conformance and non-empty <script src>

The spec says about the content model of the script element:

    If there is a src attribute, the element must be empty.

I'm not sure it is useful to ban contents of <script src> elements.

Philip` kindly provided some data, as always:  
http://philip.html5.org/data/nonempty-scripts.html


Things authors put in <script src> deliberatly:

  A: An empty comment, ";", "var dummy=0;", etc, as a way to prevent their
     server side XSLT to emit "<script ... />" (though most empty comments
     are likely just cargo cult). Banning this means that authors have to
     change their backend in order to move to HTML5, which seems to be an
     unnecessary blocker for adoption.

  B: A comment containing a description of the script and/or copyright
     information. Moving this comment to outside the script element seems
     pointless and has less chance of surviving copy-paste, and I'd imagine
     authors would get stumped when the comment says "This notice MUST stay
     intact for legal use".

  C: Empty function declarations with the same names as the functions
     declared in the external script. Personally I find this slightly
     confusing and would rather put them in a comment.

  D: "document.write(Javascript file not available);". Bogus but harmless.


Authoring mistakes:

  E: Forgetting the end tag of the previous script element. It might be
     useful if conformance checkers checked this explicitly by looking for
     "<script" that is not in an escaped text span in script src elements,
     and give a message that there's probably a </script> missing.

  F: Having an open script element because of a "<script ... />" tag.
     Conformance checkers flag this mistake already.

  G: Script that seems to be intended to be run. This doesn't seem to be
     very common, but perhaps conformance checkers can check this mistake
     somehow (e.g. by only allowing /*...*/ chunks and lines that start
     with // or <!--, at least when it's javascript)?

  H: "<noscript>...</noscript>" or other bogus markup or text.


How often the above cases occurred in the sample (I checked the first 222  
occurances in the list):


           Case           | Occurances | Percentage
-------------------------+------------+-----------
A: Empty comment or ";"  |         61 | 27%
B: Description/copyright |        137 | 62%
C: function foo() {}     |          2 | 1%
D: document.write(...)   |          2 | 1%
E: <script src><script>  |          3 | 1%
F: <script ... />        |          2 | 1%
G: script content        |          6 | 3%
H: <noscript> or other   |          9 | 4%


Conclusion: I'd like conformance checkers to not complain about case A and  
B. It would be useful if they complained about E, F, G and H. It would be  
ok if they complained about C and D, too.

-- 
Simon Pieters
Opera Software

Received on Wednesday, 14 May 2008 16:11:16 UTC