About <script> element
- language attribute is deprecated and should not be used.
- defer attribute not supported by all browsers
- using “<” in script within a XHTML throws syntax error, you should use CDATA directive
- type attribute should set to “text/javascript” to maximize browser comapatability
- using “</script>” anywhere in the script brakes code execution, if you happen to use you can use “</scri”+”pt>”
- external JavaScript inclusion looks like “< script type=”text/javascript” src=”example1.js” > < /script >”
- use
< script > < !–function sayHi(){alert(“Hi!”);}//– > < /script >
< script > < !– and //– > < /script > to make sure, non-JavaScript browsers don’t display JavaScript as body content.
Inline V/s External scripts:
External scripts provide following better maintainability and caching benefits