Why is this not working?
<script type="text/javascript" src="//cdn.com/assets/js/jquery.js"> alert("Hello World!"); </script>
But does it?
<script type="text/javascript" src="//cdn.com/assets/js/jquery.js"></script> <script type="text/javascript"> alert("Hello World!"); </script>
This is common to many HTML tags that are extracted from source code. Micro-optimization is important in my situation, and I'm also interested.
From w3.org (my attention):
If the src value has a URI value, user agents should ignore the content element and get the script through the URI.
from http://javascript.crockford.com/script.html :
"If the src attribute is missing, the content text between <script> and </script> compiled and executed."
<script>
</script>
Since the src attribute exists, the content is not executed
src
In the first example, you define src , which makes it IGNORE the contents of <script></script>
<script></script>
In the second example, you have 2 separate <script></script> , the second of which contains your code to execute.