Tuesday, November 20, 2007

Javascript Revisit 1

Just figured out that these are not equal:
<script type="text/javascript" src="cs_jscore.js"></script>
<script type="text/javascript">alert("You see me!");</script>
<script type="text/javascript">alert("Hi, see you again.");</script>
<script type="text/javascript" src="cs_jscore.js">
<script type="text/javascript">alert("I never show up!");</script>
<script type="text/javascript">alert("You see me.");</script>
Ever since the term XHTML come to my knowledge, I've maintain the practice to keep the tailing "/" to those single HTML tags like BR and HR, etc.

So I apply the same here, to sort of optimize my script in terms of size and thus the second code snippet up there. And the results are different, or rather, it won't work, at least in my firefox, the "/" closing to the single script tag will result in the subsequent script tag being ignore (since it is regarded as the text in between script tag, which is generally ignored when the src attribute of script is specified.) which it looks towards for the proper closing of script tag.

There goes my 30 mins of debugging time.


No comments: