{"id":6554,"date":"2022-09-29T09:45:58","date_gmt":"2022-09-29T09:45:58","guid":{"rendered":"https:\/\/tronsdev.com\/tronsit.au\/?p=1690"},"modified":"2022-09-29T09:45:58","modified_gmt":"2022-09-29T09:45:58","slug":"remove-render-blocking-javascript-in-wordpress","status":"publish","type":"post","link":"https:\/\/tronsdev.com\/tronsit\/remove-render-blocking-javascript-in-wordpress\/","title":{"rendered":"Remove Render Blocking JavaScript in WordPress"},"content":{"rendered":"<p>Page speed is one of the vital parameters that add value to the website\u2019s search engine optimisation. A WordPress website with good page speed is easy to crawl in for search engines, thus this increases its chances of being ranked on the SERPs- search engine result pages. Some of the common practices to shrink website load time include enabling GZIP Compression, Leverage Browser Caching and Minifying CSS, JavaScript and HTML files of a WordPress website.<br \/>\nAll these files; CSS, JavaScript and HTML, include common functionalities of a website and load as soon as a website render. Rendering refers to loading and whatever content is render-blocking means that it needlessly increases website\u2019s loading time making it slower. Hence it is important to eliminate render-blocking as soon as possible.<\/p>\n<h3>The Rendering Process<\/h3>\n<p>A website loads as a user scrolls down within a browser. The website content and layout that a user sees on the screen before scrolling any further is known as above-the-fold content. Rest, the website content and layout that is accessed by scrolling further in a website is labelled as below-the-fold content.<br \/>\nIt is highly important to fix rendering blocking for above-the-fold content on a WordPress website to make it load faster.<\/p>\n<h3>How to Remove Render blocking JavaScript in WordPress<\/h3>\n<p>JavaScript is one of the major culprits that increase a website\u2019s load time. This is because whenever browsers find a script, they tend to load it before loading HTML. JavaScript that merely defines transitions and stylises, take longer to load since they are larger in size.<br \/>\nTo remove render-blocking JavaScript, one must take steps to defer parsing JavaScript to completely optimise the loading schedule of JavaScript file. This method does not remove render-blocking but rather lets you modify your webpage rendering. For defer parsing JavaScript you need to:<\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create a complete backup to lower down the risk of damaging the website<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If you are not using a Child Theme, create and activate one<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Access the <\/span><b>WordPress Dashboard &gt; Appearance &gt; Theme Editor<\/b><b><br \/>\n<\/b><\/li>\n<li style=\"font-weight: 400;\"><b>Copy and paste <\/b><span style=\"font-weight: 400;\">the following code the end of the functions.php file.\u00a0<\/span><\/li>\n<\/ol>\n<pre><span style=\"font-weight: 400;\">function defer_parsing_js($url) {<\/span>\n\n<span style=\"font-weight: 400;\">\/\/Add the files to exclude from defer. Add jquery.js by default<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0$exclude_files = array('jquery.js');<\/span>\n\n<span style=\"font-weight: 400;\">\/\/Bypass JS defer for logged in users<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0if (!is_user_logged_in()) {<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (false === strpos($url, '.js')) {<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return $url;<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0foreach ($exclude_files as $file) {<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (strpos($url, $file)) {<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return $url;<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0} else {<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return $url;<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0}<\/span>\n\n<span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0return \"$url' defer='defer\";<\/span>\n\n<span style=\"font-weight: 400;\">}<\/span>\n\n<span style=\"font-weight: 400;\">add_filter('clean_url', 'defer_parsing_js', 11, 1);<\/span> <span style=\"font-weight: 400;\">\u00a0<\/span><\/pre>\n<ol start=\"6\">\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">JavaScript files can be specified to exclude from defer array (jquery.js)<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Click <\/span><b>update file <\/b><span style=\"font-weight: 400;\">to save changes.\u00a0<\/span><\/li>\n<li><b>Test <\/b><span style=\"font-weight: 400;\">the website using page speed tools such as <\/span><b>Google PageSpeed Insights <\/b><span style=\"font-weight: 400;\">to check if changes have successfully made the website\u2019s load time shrink.\u00a0<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">If you face any problem while implementing defer parsing JavaScript in WordPress, feel free to be part of the conversation. Comment Below!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Page speed is one of the vital parameters that add value to the website\u2019s search engine optimisation. A WordPress website with good page speed is easy to crawl in for search engines, thus this increases its chances of being ranked on the SERPs- search engine result pages. Some of the common practices to shrink website &#8230; <a title=\"Remove Render Blocking JavaScript in WordPress\" class=\"read-more\" href=\"https:\/\/tronsdev.com\/tronsit\/remove-render-blocking-javascript-in-wordpress\/\" aria-label=\"Read more about Remove Render Blocking JavaScript in WordPress\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2750,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[26],"class_list":["post-6554","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website-development","tag-website-development"],"_links":{"self":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/posts\/6554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/comments?post=6554"}],"version-history":[{"count":0,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/posts\/6554\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/media\/2750"}],"wp:attachment":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/media?parent=6554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/categories?post=6554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/tags?post=6554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}