Can the <script> tag not be self closed?
Solution 1:
In HTML, there are tags which are always self-closed. For example, <hr>Some content here</hr>
does not make any sense. In the same way, there are tags which cannot be self-closed. <script>
tag is one of them.
I am not sure about the reason of no self-closed <script>
tags, but the reason might come from the fact that the tag was intended to always contain code inside. Again, I'm not sure.
Solution 2:
Because it gets parsed as:
Line 1: Start tag for script
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"/>
Line 2: JavaScript (really broken JavaScript!) to execute if the external script mentioned on line 1 fails to load
<script type='text/javascript' src='/lib/player/swfobject.js'>
Line 3: End tag for script started on line 1
</script>
Okay, granted a tag that is closed and a self closing tag are not the same.
They are the same (if there is no content), but only in XML documents. An XHTML document served as application/xhtml+xml is an XML document. In an HTML document, thanks to a legacy of improper implementations by browsers, a self-closing tag is just a start tag (and so is only OK when the end tag is forbidden).
Solution 3:
David Dorward's answer explains this from one angle, but there is a deeper reason why you can't do this:
A slash at the end of a tag does not make it self-closing in HTML
The self-closing syntax is part of XML. In a normal HTML document, it has no meaning.