I would put a dummy comment inside the script tag. so
instead of <script src="foo.js"/> say
<script src="foo.js"><!-- placeholder--></script>
because that will avoid the serializer or browser being misled
by an empty element.
I don't pretend to understand why your thing doesn't work,
but if this solves it, at least you can move on.
Director (Research) of Academic IT
University of Oxford IT Services
13 Banbury Road, Oxford OX2 6NN. Phone +44 1865 283431