Browse DevX
Sign up for e-mail newsletters from DevX

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.

function UsedLater()
   // utility function called when the user interacts with the page

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






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



Thanks for your registration, follow us on our social networks to keep up-to-date