Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: All
Jun 18, 1999

Optimize Your Scripts in DHTML Using the DEFER Attribute

DEFER is a relatively obscure attribute of the SCRIPT element, but if you want to enhance performance when authoring scripts, you can use it to indicate to Internet Explorer 4 or later that the SCRIPT tag contains no immediately executing code that impacts the document before the load event fires. Combined with the SRC attribute, you can use the DEFER attribute on a SCRIPT tag to indicate to IE that the associated code should be downloaded in the background while the rest of the components of the page are downloaded and parsed.

The HTML 4.0 Specification makes specific reference to the write method of the document object. When you mark your scripts as deferred, you should not include any calls to document.write because these calls are typically executed immediately as the page is loading. In addition, you shouldn't defer any global variables or functions that are accessed by immediately executing script.

 
<SCRIPT DEFER>
function UsedLater()
{
   // utility function called when the user interacts with the page
}
</SCRIPT>

<SCRIPT>
   // Can't defer this block. It runs immediately and affects the shape of the
document.
   document.write("<H1>Immediate Gratification</H1>");
</SCRIPT>
Jai Bardhan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap