<script name="my_script" src="path/or/url/to/my_script.js"></script>
nameattribute is optional and is intended for humans only.
<script> document.write('\x3Cscript src="my_other_script.js">\x3C/script>'); </script>
You can dynamically create a script tag and run it.
- You can use as many script tags in a document as you feel necessary.
- The browser reads each script tag in the order in which it appears in the document. If a script is defining functions or data that are used by another script, then the defining must be done before use. So the defining scripts must come before the using scripts.
- Do not use the
<!-- //-->hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic.
CDATAis needed for XHTML pages if the script has any HTML characters like
<script>//<![CDATA[ ...code... //]]></script>
- JS security ( Same-origin policy ) prevent scripts hosted at other domains from running unless you setup CORS.