Optimize Your Scripts in DHTML Using the DEFER Attribute

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 areaccessed by immediately executing script.



Share the Post: