{"id":656,"date":"2019-11-25T06:27:10","date_gmt":"2019-11-25T06:27:10","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/wordpresshow-to-defer-parsing-of-javascript-in-wordpress\/"},"modified":"2025-04-23T09:14:55","modified_gmt":"2025-04-23T09:14:55","slug":"how-to-defer-parsing-of-javascript","status":"publish","type":"post","link":"\/uk\/tutorials\/how-to-defer-parsing-of-javascript","title":{"rendered":"How to Improve Your Site&#8217;s Speed in WordPress by Deferring JavaScript Parsing"},"content":{"rendered":"<p>If you want to cut your website&rsquo;s loading time, you can try to defer parsing of JavaScript. It allows the browser to render JavaScript <strong>only<\/strong> after it finishes loading the main content of a site. In this tutorial, we will cover several ways on how to defer parsing of JavaScript in WordPress CMS.<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Mega-WordPress-Cheat-EN.pdf\" target=\"_blank\" rel=\"noopener\">Download all in one WordPress cheat sheet<\/a><\/p><p>\n\n\n\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-why-should-you-defer-parsing-of-javascript\">Why Should You Defer Parsing of JavaScript?<\/h2><p>When you open a website, your browser will receive the site&rsquo;s content from the server and loads the code from top to bottom. However, if it finds JavaScript, the loading process will be interrupted until it finishes downloading all the JavaScript.<\/p><p>To solve this issue, you can defer parsing of JavaScript, which allows the browser to load the full content without waiting for the scripts to load. By implementing this task, JavaScript parsing won&rsquo;t negatively affect your website&rsquo;s loading time.<\/p><p>Keep in mind that having lots of JavaScript isn&rsquo;t bad. After all, It&rsquo;s one of the essential <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Web_Components\" target=\"_blank\" rel=\"noreferrer noopener\">web components<\/a>, which allows you to extend the functionality of your site.<\/p><p>The point is, there are two main benefits you can get:<\/p><ul class=\"wp-block-list\">\n<li><strong>Better user experience<\/strong> &ndash; visitors won&rsquo;t have to wait long to view your website content.<\/li>\n\n\n\n<li><strong>Improved SEO ranking<\/strong> &ndash; <a href=\"https:\/\/developers.google.com\/search\/docs\/crawling-indexing\/googlebot\" target=\"_blank\" rel=\"noreferrer noopener\">Google bots<\/a> can crawl your site faster.<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-how-to-defer-parsing-of-javascript-in-wordpress\">How to Defer Parsing of JavaScript in WordPress?<\/h2><p>This section will show you a step-by-step guide to defer parsing of JavaScript. To top it off, we&rsquo;ll also show you how to analyze the problem and test the changes after applying the task.<\/p><h3 class=\"wp-block-heading\" id=\"h-1-analyze-the-site\">1. Analyze the site<\/h3><p>To find out whether you should defer parsing of JavaScript in your WordPress website, analyze it using <a href=\"\/uk\/tutorials\/website-speed-test\/\" target=\"_blank\" rel=\"noreferrer noopener\">site speed testing tools<\/a> like <a href=\"https:\/\/www.gtmetrix.com\" target=\"_blank\" rel=\"noreferrer noopener\">GTMetrix<\/a>. As an example, here is the performance result of a website before implementing the method:<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"1120\" height=\"373\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2016\/10\/analyze-defer-parsing-of-javascript-in-gtmetrix.png\" alt=\"GTMetrix recommending to defer parsing of JavaScript to reduce blocking of page rendering\" class=\"wp-image-22821\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/analyze-defer-parsing-of-javascript-in-gtmetrix.png 1120w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/analyze-defer-parsing-of-javascript-in-gtmetrix-150x50.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/analyze-defer-parsing-of-javascript-in-gtmetrix-300x100.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/analyze-defer-parsing-of-javascript-in-gtmetrix-768x256.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/analyze-defer-parsing-of-javascript-in-gtmetrix-1024x341.png 1024w\" sizes=\"(max-width: 1120px) 100vw, 1120px\" \/><\/figure><\/div><p>It shows that there&rsquo;s an issue regarding JavaScript parsing, which means the website site needs to defer it.<\/p><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/uk\/wordpress-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner-1024x300.png\" alt=\"\" class=\"wp-image-111781\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/06\/New-WP_in-text-banner-1024x300.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/06\/New-WP_in-text-banner-300x88.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/06\/New-WP_in-text-banner-150x44.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/06\/New-WP_in-text-banner-768x225.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/06\/New-WP_in-text-banner-1536x450.png 1536w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2024\/06\/New-WP_in-text-banner.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h3 class=\"wp-block-heading\" id=\"h-2-defer-parsing-of-javascript-in-wordpress\">2. Defer Parsing of JavaScript in WordPress<\/h3><p>Now, let&rsquo;s get into the steps of deferring parsing of JavaScript! There are two ways to do it &ndash; installing a plugin or adding a code snippet manually.<\/p><h4 class=\"wp-block-heading\" id=\"h-using-wordpress-plugins\">Using WordPress plugins<\/h4><div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"940\" height=\"305\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2016\/10\/banner-of-speed-booster-pack.jpg\" alt=\"Speed Booster Pack WordPress plugin\" class=\"wp-image-22829\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/banner-of-speed-booster-pack.jpg 940w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/banner-of-speed-booster-pack-150x49.jpg 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/banner-of-speed-booster-pack-300x97.jpg 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/banner-of-speed-booster-pack-768x249.jpg 768w\" sizes=\"(max-width: 940px) 100vw, 940px\" \/><\/figure><\/div><p>One of the easiest ways to defer JavaScript parsing is by using a plugin. <a href=\"https:\/\/wordpress.org\/plugins\/speed-booster-pack\/\" target=\"_blank\" rel=\"noreferrer noopener\">Speed Booster Pack<\/a> is one of the most popular plugins for this task. To begin, <a href=\"\/uk\/tutorials\/wordpress\/how-to-install-wordpress-plugins\" target=\"_blank\" rel=\"noreferrer noopener\">install the plugin<\/a> and activate it, then follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>Go to your WordPress Dashboard.<\/li>\n\n\n\n<li>On the left sidebar, navigate to <strong>Speed Booster<\/strong>.<\/li>\n\n\n\n<li>Click the <strong>Advanced <\/strong>tab, and activate <strong>Defer parsing of JS files.<br><img decoding=\"async\" width=\"1017\" height=\"838\" class=\"aligncenter size-full wp-image-22830\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2016\/10\/defer-parsing-of-wordpress-javascript-using-speed-booster-pack-plugin.png\" alt=\"defer parsing of wordpress javascript using speed booster pack plugin\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/defer-parsing-of-wordpress-javascript-using-speed-booster-pack-plugin.png 1017w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/defer-parsing-of-wordpress-javascript-using-speed-booster-pack-plugin-150x124.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/defer-parsing-of-wordpress-javascript-using-speed-booster-pack-plugin-300x247.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/defer-parsing-of-wordpress-javascript-using-speed-booster-pack-plugin-768x633.png 768w\" sizes=\"(max-width: 1017px) 100vw, 1017px\" \/><\/strong><\/li>\n\n\n\n<li>Once done, tap <strong>Save Changes<\/strong>.<\/li>\n<\/ol><h4 class=\"wp-block-heading\" id=\"h-defer-parsing-of-javascript-via-functions-php\">Defer Parsing of JavaScript via functions.php<\/h4><p>Alternatively, you can carry out the task manually by editing one of the WordPress core files. Make sure to <a href=\"\/uk\/tutorials\/backups\/downloading-website-backup\" target=\"_blank\" rel=\"noreferrer noopener\">backup your website<\/a> before proceeding. Here are the steps:<\/p><ol class=\"wp-block-list\">\n<li>From your WordPress admin area, go to <strong>Appearance -&gt; Theme Editor<\/strong><\/li>\n\n\n\n<li>Select <a href=\"\/uk\/tutorials\/functions-php-wordpress\">functions.php<\/a><strong> <\/strong>in the <strong>Theme Files<br><img decoding=\"async\" width=\"1892\" height=\"717\" class=\"aligncenter size-full wp-image-22834\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2016\/10\/open-theme-editor-to-defer-parsing-of-javascript.png\" alt=\"open theme editor to defer parsing of javascript\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/open-theme-editor-to-defer-parsing-of-javascript.png 1024w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/open-theme-editor-to-defer-parsing-of-javascript-150x57.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/open-theme-editor-to-defer-parsing-of-javascript-300x114.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/open-theme-editor-to-defer-parsing-of-javascript-768x291.png 768w\" sizes=\"(max-width: 1892px) 100vw, 1892px\" \/><\/strong><\/li>\n\n\n\n<li>Enter this code at the bottom of the file:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">function defer_parsing_of_js ( $url ) {\nif ( FALSE === strpos( $url, '.js' ) ) return $url;\nif ( strpos( $url, 'jquery.js' ) ) return $url;\nreturn \"$url' defer \";\n}\nadd_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );<\/pre>\n<\/li>\n\n\n\n<li>Click <strong>Update File<\/strong>.<\/li>\n<\/ol><h3 class=\"wp-block-heading\" id=\"h-3-test-the-changes\">3. Test the Changes<\/h3><p>After using one of the above options, <a href=\"\/uk\/tutorials\/gtmetrix-for-testing-websites-speed\">re-analyze your site with GTMetrix<\/a>:<\/p><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"1069\" height=\"128\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2016\/10\/successful-defer-parsing-of-javascript-in-gtmetrix.png\" alt=\"Successful defer parsing of JavaScript in GTmetrix.\" class=\"wp-image-22832\" srcset=\"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/successful-defer-parsing-of-javascript-in-gtmetrix.png 1069w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/successful-defer-parsing-of-javascript-in-gtmetrix-150x18.png 150w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/successful-defer-parsing-of-javascript-in-gtmetrix-300x36.png 300w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/successful-defer-parsing-of-javascript-in-gtmetrix-768x92.png 768w, https:\/\/www.hostinger.com\/uk\/tutorials\/wp-content\/uploads\/sites\/51\/2016\/10\/successful-defer-parsing-of-javascript-in-gtmetrix-1024x123.png 1024w\" sizes=\"(max-width: 1069px) 100vw, 1069px\" \/><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>In this tutorial, you&rsquo;ve learned how to <a href=\"\/uk\/tutorials\/speed-up-wordpress\" target=\"_blank\" rel=\"noreferrer noopener\">improve your WordPress site speed<\/a> by deferring parsing of JavaScript. You can do so by using a plugin or adding a code snippet to the theme&rsquo;s functions.php file.<\/p><p>Keep in mind that improving your website&rsquo;s loading time will lead to better user experience and improved SEO ranking.<\/p><p>Do you have any questions regarding this topic? Share your thoughts in the comment section below!<\/p><p>\n\n\n<div class=\"protip\">\n                    <h4 class=\"title\">Discover More Expert WordPress Techniques<\/h4>\n                    <p><a href=\"\/uk\/tutorials\/wordpress-javascript\">How to Add JavaScript to WordPress<\/a><br>\n<a href=\"\/uk\/tutorials\/external-javascript-wordpress\">Combine External JavaScript in WordPress<\/a><br>\n<a href=\"\/uk\/tutorials\/remove-query-strings-static-resources\">Remove Query Strings From Static Resources<\/a><br>\n<a href=\"\/uk\/tutorials\/how-to-fix-admin-ajax-file\">How to Fix Admin Ajax File in WordPress<\/a><br>\n<a href=\"\/uk\/tutorials\/how-to-fix-eliminate-render-blocking-javascript-and-css-in-above-the-fold-content-on-wordpress\">How to Eliminate Render Blocking JavaScript and CSS<\/a><\/p>\n                <\/div>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to cut your website&rsquo;s loading time, you can try to defer parsing of JavaScript. It allows the browser to render JavaScript only after it finishes loading the main content of a site. In this tutorial, we will cover several ways on how to defer parsing of JavaScript in WordPress CMS. Why Should [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/uk\/tutorials\/how-to-defer-parsing-of-javascript\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Defer Parsing of JavaScript in WordPress","rank_math_description":"Learn how to defer parsing of JavaScript in WordPress. Deferred JavaScript may significantly increase WordPress speed and performance.","rank_math_focus_keyword":"defer parsing of javascript","footnotes":""},"categories":[22636,22633],"tags":[],"class_list":["post-656","post","type-post","status-publish","format-standard","hentry","category-security-and-maintenance","category-wordpress"],"hreflangs":[],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/comments?post=656"}],"version-history":[{"count":28,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/656\/revisions"}],"predecessor-version":[{"id":104433,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/posts\/656\/revisions\/104433"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/media?parent=656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/categories?post=656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/uk\/tutorials\/wp-json\/wp\/v2\/tags?post=656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}