What ? (are these)
Basically async and defer are attributes that can be used by <script> to improve page speed by decreasing loading lag.
Why? (do we use)
We add this attribute to script tag in HTML to control script loading and executing.
How? (it works)
async : This attribute tells browser to download script file asynchronously while continuing to parse the HTML page. Once script has downloaded it executes immediately regardless page parsing.
defer : This attribute also tells browser to download script file asynchronously while continuing to parse the HTML page. Name is self-evidently, it defers execution of script until HTML page has finished parsing.
When? (to use)
async : The script can run before DOM has fully loaded and it doesnβt execute in order. Suitable for scripts which do not perform DOM manipulation.
defer : The script always executes in order in which they appear in HTML. Suitable for scripts which perform DOM manipulation.
Quick Visualization
11 Comments
Thanks so much for the blog article.Really looking forward to read more. Cool.
Heya i’m for the first time here. I came across this board and I in finding It really helpful & it helped meout much. I’m hoping to present something back and help otherssuch as you helped me.
Hey There. I found your blog using msn. This is a very well written article.I’ll make sure to bookmark it and come back to read more of youruseful information. Thanks for the post. I’ll definitely comeback.
This article is in fact a pleasant one it helps new net people, who are wishing in favor of blogging.
constantly i used to read smaller articles or reviews which also clear their motive, and that isalso happening with this paragraph which I am reading at this time.
Major thankies for the post.Really thank you! Cool.
Fantastic blog post.Thanks Again. Awesome.
Major thankies for the post.Thanks Again. Want more.
A round of applause for your article.Really looking forward to read more. Will read on…
Appreciate you sharing, great article.
Hey, thanks for the blog article.Thanks Again. Much obliged.