{"id":2287,"date":"2019-01-14T11:39:59","date_gmt":"2019-01-14T19:39:59","guid":{"rendered":"https:\/\/www.virendrachandak.com\/techtalk\/?p=2287"},"modified":"2019-01-14T11:57:23","modified_gmt":"2019-01-14T19:57:23","slug":"async-vs-defer","status":"publish","type":"post","link":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/","title":{"rendered":"How to remove render blocking JavaScript with defer and async"},"content":{"rendered":"<p>With HTML5 there are 2 new boolean attributes for <code>&lt;script><\/code> tag which indicates to the browser how the script should be evaluated. The 2 attributes are <code>defer<\/code> and <code>async<\/code>. Using these attributes can help improve the page load time by downloading the script in parallel when the page is being parsed and then executing it either immediately or at the end of page parsing.<br \/>\n<!--more--><\/p>\n<p>If the <code>defer<\/code> attribute is present, then the script is fetched in parallel to the parsing of the page but will be evaluated only after the page is parsed. When <code>async<\/code> attribute is present, then the script is fetched in parallel to the parsing of the page and it will be evaluated as soon as the script is available (potentially before the page is parsed completely). If both <code>defer<\/code> and <code>async<\/code> attributes are not present then the script is fetched and evaluated immediately, and hence blocking the parsing of the page while the script is being downloaded and evaluated.<\/p>\n<p>Here is a quick summary of how the script tag works with and without <code>defer<\/code> and <code>async<\/code> attributes<\/p>\n<p><img src='https:\/\/www.virendrachandak.com\/images\/async-defer.svg' \/><\/p>\n<p>The <code>defer<\/code> and <code>async<\/code> attributes can be specified together. When both are present the <code>async<\/code> tag take preference over <code>defer<\/code>. For the older browsers that don&#8217;t support <code>async<\/code>, but support <code>defer<\/code>, it will fallback to <code>defer<\/code> behavior instead of the default blocking behavior.<\/p>\n<p>With <code>defer<\/code> attribute the order of execution of the script remain the same, but with <code>async<\/code> the order of execution of the script is not guaranteed. Hence, using <code>defer<\/code> is best for the cases where a script depends on another. e.g. if you have jQuery and a script that depends on it, then you should use <code>defer<\/code> on those scripts (including jQuery) to make sure that jQuery is loaded before the dependent scripts.<\/p>\n<p>Both the <code>defer<\/code> and <code>async<\/code> parameters should be specified only if using the src tag. If used without the source tag (on inline scripts) they won&#8217;t affect the execution of the scripts.<\/p>\n<div style=\"padding-top:15px;\">\n<strong>Reference Links<\/strong>:<\/p>\n<ul>\n<li><a title=\"script tag - HTML standard\" href=\"https:\/\/html.spec.whatwg.org\/multipage\/scripting.html#attr-script-defer\" rel=\"external nofollow\" target=\"_blank\">script tag &#8211; HTML standard<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>With HTML5 there are 2 new boolean attributes for &lt;script> tag which indicates to the browser how the script should be evaluated. The 2 attributes are defer and async. Using these attributes can help improve the page load time by downloading the script in parallel when the page is being parsed and then executing it [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[144,5,138,8],"tags":[155,156,10],"class_list":["post-2287","post","type-post","status-publish","format-standard","hentry","category-javascript","category-optimization-tips","category-seo","category-web-development","tag-async","tag-defer","tag-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to remove render blocking JavaScript with defer and async - Virendra&#039;s TechTalk<\/title>\n<meta name=\"description\" content=\"Eliminating render blocking JavaScript with async and defer attributes to delay execution of scripts which helps improve performance and page load times.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to remove render blocking JavaScript with defer and async - Virendra&#039;s TechTalk\" \/>\n<meta property=\"og:description\" content=\"Eliminating render blocking JavaScript with async and defer attributes to delay execution of scripts which helps improve performance and page load times.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/\" \/>\n<meta property=\"og:site_name\" content=\"Virendra&#039;s TechTalk\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/virendrachandak\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-14T19:39:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-01-14T19:57:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.virendrachandak.com\/images\/async-defer.svg\" \/>\n<meta name=\"author\" content=\"Virendra Chandak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:site\" content=\"@virendrachandak\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virendra Chandak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/\"},\"author\":{\"name\":\"Virendra Chandak\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"headline\":\"How to remove render blocking JavaScript with defer and async\",\"datePublished\":\"2019-01-14T19:39:59+00:00\",\"dateModified\":\"2019-01-14T19:57:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/\"},\"wordCount\":325,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"image\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.virendrachandak.com\\\/images\\\/async-defer.svg\",\"keywords\":[\"async\",\"defer\",\"JavaScript\"],\"articleSection\":[\"JavaScript\",\"Optimization Tips\",\"SEO\",\"Web Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/\",\"url\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/\",\"name\":\"How to remove render blocking JavaScript with defer and async - Virendra&#039;s TechTalk\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.virendrachandak.com\\\/images\\\/async-defer.svg\",\"datePublished\":\"2019-01-14T19:39:59+00:00\",\"dateModified\":\"2019-01-14T19:57:23+00:00\",\"description\":\"Eliminating render blocking JavaScript with async and defer attributes to delay execution of scripts which helps improve performance and page load times.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.virendrachandak.com\\\/images\\\/async-defer.svg\",\"contentUrl\":\"https:\\\/\\\/www.virendrachandak.com\\\/images\\\/async-defer.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/async-vs-defer\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"TechTalk\",\"item\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/category\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to remove render blocking JavaScript with defer and async\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#website\",\"url\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/\",\"name\":\"Virendra's TechTalk\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/63f7ffa1ea125e32af9618d188349e17\",\"name\":\"Virendra Chandak\",\"logo\":{\"@id\":\"https:\\\/\\\/www.virendrachandak.com\\\/techtalk\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.virendrachandak.com\",\"https:\\\/\\\/www.facebook.com\\\/virendrachandak\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/virendrachandak\\\/\",\"https:\\\/\\\/x.com\\\/virendrachandak\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to remove render blocking JavaScript with defer and async - Virendra&#039;s TechTalk","description":"Eliminating render blocking JavaScript with async and defer attributes to delay execution of scripts which helps improve performance and page load times.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/","og_locale":"en_US","og_type":"article","og_title":"How to remove render blocking JavaScript with defer and async - Virendra&#039;s TechTalk","og_description":"Eliminating render blocking JavaScript with async and defer attributes to delay execution of scripts which helps improve performance and page load times.","og_url":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/","og_site_name":"Virendra&#039;s TechTalk","article_publisher":"https:\/\/www.facebook.com\/virendrachandak","article_author":"https:\/\/www.facebook.com\/virendrachandak","article_published_time":"2019-01-14T19:39:59+00:00","article_modified_time":"2019-01-14T19:57:23+00:00","og_image":[{"url":"https:\/\/www.virendrachandak.com\/images\/async-defer.svg","type":"","width":"","height":""}],"author":"Virendra Chandak","twitter_card":"summary_large_image","twitter_creator":"@virendrachandak","twitter_site":"@virendrachandak","twitter_misc":{"Written by":"Virendra Chandak","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#article","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/"},"author":{"name":"Virendra Chandak","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"headline":"How to remove render blocking JavaScript with defer and async","datePublished":"2019-01-14T19:39:59+00:00","dateModified":"2019-01-14T19:57:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/"},"wordCount":325,"commentCount":0,"publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"image":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#primaryimage"},"thumbnailUrl":"https:\/\/www.virendrachandak.com\/images\/async-defer.svg","keywords":["async","defer","JavaScript"],"articleSection":["JavaScript","Optimization Tips","SEO","Web Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/","url":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/","name":"How to remove render blocking JavaScript with defer and async - Virendra&#039;s TechTalk","isPartOf":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#primaryimage"},"image":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#primaryimage"},"thumbnailUrl":"https:\/\/www.virendrachandak.com\/images\/async-defer.svg","datePublished":"2019-01-14T19:39:59+00:00","dateModified":"2019-01-14T19:57:23+00:00","description":"Eliminating render blocking JavaScript with async and defer attributes to delay execution of scripts which helps improve performance and page load times.","breadcrumb":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#primaryimage","url":"https:\/\/www.virendrachandak.com\/images\/async-defer.svg","contentUrl":"https:\/\/www.virendrachandak.com\/images\/async-defer.svg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.virendrachandak.com\/techtalk\/async-vs-defer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"TechTalk","item":"https:\/\/www.virendrachandak.com\/techtalk\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.virendrachandak.com\/techtalk\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"How to remove render blocking JavaScript with defer and async"}]},{"@type":"WebSite","@id":"https:\/\/www.virendrachandak.com\/techtalk\/#website","url":"https:\/\/www.virendrachandak.com\/techtalk\/","name":"Virendra's TechTalk","description":"","publisher":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.virendrachandak.com\/techtalk\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/63f7ffa1ea125e32af9618d188349e17","name":"Virendra Chandak","logo":{"@id":"https:\/\/www.virendrachandak.com\/techtalk\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.virendrachandak.com","https:\/\/www.facebook.com\/virendrachandak","https:\/\/www.linkedin.com\/in\/virendrachandak\/","https:\/\/x.com\/virendrachandak"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2vTtQ-AT","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/2287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/comments?post=2287"}],"version-history":[{"count":0,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/posts\/2287\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/media?parent=2287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/categories?post=2287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virendrachandak.com\/techtalk\/wp-json\/wp\/v2\/tags?post=2287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}