I\'d like to include a javascript file on every page of a site. I can do this with:
Unfortunately, the HTML specs for REQUIRE a closing tag...
HTML Standard, section 18.2.1
18.2.1 The SCRIPT element
Start tag: required, End tag: required
This is not a bug, it's standard behavior.
Also, empty HTML elements are often not rendered:
<div style="background:red"></div>
displays, <div style="background:red" />
doesn't
HTML
doesn't support self closing tags. If you want to use them you need to use an xml based doctype AND serve the file as xml.
XHTML or the xml serialisation of html5 would both work.
Here is an example:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XHTML5 Template</title>
<meta charset="utf-8" />
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js" />
</head>
<body>
</body>
</html>
Save this in a file with a .xhtml
extension and open it in a modern browser and the self closing tag will work.