Enable Defer Parsing JS to Footer

JavaScript Defer Parsing is the most recent improvement in how JavaScript handles asynchronous code. It is a part of ECMAScript, and it has a variety of benefits over the previous way of handling async code.

This can speed up your page render for visitors. Without further explanation, just copy the following code and paste inside your function.php file.

				
					/** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer **/
add_filter('script_loader_tag', 'jltwp_adminify_defer_parsing_of_js', 10, 2);

/** Secure method for Defer Parsing of JavaScript moving ALL JS from Header to Footer **/
function jltwp_adminify_defer_parsing_of_js($tag, $handle)
{
    if (is_admin()) {
        return $tag;
    }
    if (strpos($tag, '/wp-includes/js/jquery/jquery')) {
        return $tag;
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9.') !== false) {
        return $tag;
    } else {
        return str_replace(' src', ' defer src', $tag);
    }
}
				
			

WP Adminify Defer Parsing JS to Footer

Install WP Adminify plugin first and navigate to WP Adminify > Tweaks > Performance. Search for “Enable Defer Parsing JS to Footer” option and enable it. 

Enable Defer Parsing JS to Footer

That’s how to configure defer parsing JS to footer instead of the header. 

August 28, 2021
Performance
Was this article helpful?

© 2021-2024 - Adminify | All rights reserved

WP Adminfy accepted payment methods