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.

See also  Comparing different methods of testing your Infrastructure-as-Code

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist