{"id":4981,"date":"2024-11-19T23:42:18","date_gmt":"2024-11-19T18:12:18","guid":{"rendered":"https:\/\/namastedev.com\/blog\/?p=4981"},"modified":"2024-11-19T23:42:18","modified_gmt":"2024-11-19T18:12:18","slug":"tag-attribute-async-v-s-defer","status":"publish","type":"post","link":"https:\/\/namastedev.com\/blog\/tag-attribute-async-v-s-defer\/","title":{"rendered":"tag attribute async v\/s defer"},"content":{"rendered":"<p><\/p>\n<h1><span class=\"ql-font-monospace\">What ? (are these)<\/span><\/h1>\n<p><span class=\"ql-font-monospace\">Basically async and defer are attributes that can be used by &lt;script&gt; to improve page speed by decreasing loading lag.<\/span><\/p>\n<p><\/p>\n<h1><span class=\"ql-font-monospace\">Why? (do we use)<\/span><\/h1>\n<p><span class=\"ql-font-monospace\">We add this attribute to script tag in HTML to control script loading and executing.<\/span><\/p>\n<h1><\/h1>\n<h1><span class=\"ql-font-monospace\">How? (it works)<\/span><\/h1>\n<p><strong class=\"ql-font-monospace\">async :<\/strong><span class=\"ql-font-monospace\"> 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.<\/span><\/p>\n<p><\/p>\n<p><strong class=\"ql-font-monospace\">defer :<\/strong><span class=\"ql-font-monospace\"> 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.<\/span><\/p>\n<p><\/p>\n<h1><span class=\"ql-font-monospace\">When? (to use)<\/span><\/h1>\n<p><strong class=\"ql-font-monospace\">async :<\/strong><span class=\"ql-font-monospace\"> The script can run before DOM has fully loaded and it doesn\u2019t execute in order. Suitable for scripts which do not perform DOM manipulation.<\/span><\/p>\n<p><\/p>\n<p><strong class=\"ql-font-monospace\">defer : <\/strong><span class=\"ql-font-monospace\">The script always executes in order in which they appear in HTML. Suitable for scripts which perform DOM manipulation.<\/span><\/p>\n<p><\/p>\n<p><span class=\"ql-font-monospace\">Quick Visualization<\/span><\/p>\n<p><\/p>\n<p><span class=\"ql-font-monospace\"><img decoding=\"async\" src=\"https:\/\/namastedev.com\/blog\/wp-content\/uploads\/2024\/09\/nishi_surti_Blog.webp\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What ? (are these) Basically async and defer are attributes that can be used by &lt;script&gt; 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<\/p>\n","protected":false},"author":51,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[333,172],"tags":[330],"class_list":["post-4981","post","type-post","status-publish","format-standard","category-asynchronous-javascript","category-javascript","tag-javascript"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/comments?post=4981"}],"version-history":[{"count":1,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4981\/revisions"}],"predecessor-version":[{"id":5005,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4981\/revisions\/5005"}],"wp:attachment":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/media?parent=4981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/categories?post=4981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/tags?post=4981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}