Search code examples
javascriptexternal-scripthtml-head

Best way to link to external scripts in Document HEAD


I've noticed many sites use this, without closing the tag.

 <script type="text/javascript" src="editor.js">

This style is also recommended but is longer:

 <script type="text/javascript" src="editor.js"></script>

Can I write it like this? Is it valid or is there a better way?

 <script type="text/javascript" src="editor.js" />

Solution

  • You always want to use

    <script type="text/javascript" src="editor.js"></script>
    

    Some browsers do not allow self-closing script tags.

    For more information, see Why don't self-closing script tags work?