What are defer and async attributes on a tag?
What are defer and async attributes on a tag?
The defer and async attributes are used on a <script> tag to control the loading and execution of JavaScript files without interfering with the initial rendering of the HTML page.
The defer attribute tells the browser to download the script in the background while it continues to parse and render the rest of the HTML document. The script execution is deferred until after the document has been fully parsed. This means that scripts with the defer attribute will not block the rendering of the page, and they will execute in the order they appear in the document, maintaining script execution order. The defer attribute is particularly useful when you have multiple scripts that depend on each other, as it ensures they run in the correct sequence after the document is ready.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.