script defer attribute
The defer attribute on the script element:
- → allows you to defer the execution of an external script linked to the page
- is a specific attribute → can be applied ONLY on the next html element: script
- is optional
!Observations
- defer attribute can be specified only if src attribute is present (for external scripts only)
- defer attribute should be specified when targeting an asynchronous execution (async attribute present), because in case async is not supported in browser (e.g.IE9) it will fallback to defer instead of the default blocking behaviour
- when both defer and async attributes are present, the async attribute represent de default behavior
Examples
< | attribute | = | "value(s)" | > | ... | </ | >Examples |
---|---|---|---|---|---|---|---|
4. | defer | = | "", , defer | <src="script.js" defer> <⁄ > <src="script.js" defer=""> <⁄ > <src="script.js" defer="defer"> <⁄ > |