For reference, adding a completely empty text node does the job, it doesn't even need to have a space in it.
OK changing $script = $document->createElement ( 'script', '' ); to $script = $document->createElement ( 'script', ' ' ); produces <script src="script.js"> </script> Thanks for that. Now how can I get DOmDocument to produce <script src="script.js"></script> i.e. without the extra space?
That I don't know. Wonder if it does that for all tags, or are JS tags buggy? Try creating a <p> with no content and see if that self closes.