Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having Script within a Script Src tag? <script> (JavaScript etc)

Why does this not work?

<script type="text/javascript" src="//cdn.com/assets/js/jquery.js">
alert("Hello World!");
</script>

But this does?

<script type="text/javascript" src="//cdn.com/assets/js/jquery.js"></script>
<script type="text/javascript">
alert("Hello World!");
</script>

This is general across many HTML tags that pull from source. Micro optimization is important in my situation and I am also curious.

like image 566
TheBlackBenzKid Avatar asked Aug 29 '12 15:08

TheBlackBenzKid


1 Answers

From w3.org (emphasis mine):

If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.

like image 93
D'Arcy Rittich Avatar answered Sep 27 '22 22:09

D'Arcy Rittich