Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Improved JavaScript/IE Efficiency 1

Status
Not open for further replies.

mbgxp

Programmer
Jun 25, 2003
2
GB
If I code a simple HTML DIV like this:

Code:
<div id=DivC align=&quot;left&quot; CLASS=&quot;DivClass&quot; style=HEIGHT:20PX;width:100%>C</div>

it works fine. No problem. And if in IE I 'view source', the above is what it shows me.

However, if in JavaScript I display the outerHTML of the DIV, it shows me this:

Code:
<DIV class=DivClass id=DivC style=&quot;WIDTH: 100%; HEIGHT: 20px&quot; align=left>C</DIV>

Note that:
1. Some case has been changed from lower to upper, e.g. div becomes DIV.
2. Some case has been changed from upper to lower, e.g. CLASS becomes class.
3. Some elements have been moved, e.g. align=left is now last.
4. Some double quotes have been removed, e.g. align=&quot;left&quot; becomes align=left.
5. Spaces have been inserted into the &quot;style&quot;.

My conclusion is that either IE or JavaScript is converting my source code into a standard format. Again, I have no problem with that but my two questions are:

a) If I write my source code TO START OFF WITH in the &quot;standard&quot; format it seems to end up as, will this help IE/JavaScript to run more efficiently?

b) How can I compare the performance of &quot;standard&quot; and &quot;non-standard&quot; format?
 
there is no &quot;standard&quot; format: attributes can appear in any order, and this has no effect on performance.

the only thing i would suggest is to start going the xhtml route: make sure all tag names and attributes are lower case, make sure all attributes are quoted:

<div id=&quot;DivC&quot; align=&quot;left&quot; class=&quot;DivClass&quot; style=&quot;HEIGHT:20PX;width:100%&quot;>C</div>

see for more info


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
hey guys,

Internet Explorer transforms the HTML it receives into its own format. When you display outerHTML you do not actually display the HTML in the source code but the HTML as IE understands it. I believe this is bad practice on MS's part but there isn't much you can do about it.

Gary Haran
********************************
 
OK, so reading between the lines ...

Supposing I want to distinguish between HTML and XHTML, then I do not want to go for total lower case in my HTML.

Since browsers will tolerate all sorts of variations of case, sequence and quotation marks, the innerHTML displayed by JavaScript can not be wrong.

If Microsoft IE has cornered 80% of the browser market, following the IE convention (as revealed by innerHTML) is likely to satisfy 80% of my visitors.

The question still remains, if I start off in my source HTML with the identical syntax that IE converts HTML to anyway, does that help IE? In other words, if IE has no work to do converting my source to its source, does it run more efficiently?
 
i don't think anything you do to your html is going to affect browser performance, and i would advise adopting xhtml convention now to get in the habit.


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Keep plugging xhtml; habits die slowly, and bad habits die hardest. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top