In this article, We Learn about How to add defer parsing code in WordPress.
The main purpose of using defer parsing javascript is to reduce page load time and content load fast without waiting for the scripts to be loaded.
For that, we can use “defer” or “async“.
Here is a code for Defer Parsing and this code need to add to the functions.php file:
function thc_defer_parsing_of_js ( $url ) { if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.min.js' ) ) return $url; return str_replace( ' src', ' defer src', $url ); } add_filter( 'clean_url', 'thc_defer_parsing_of_js', 11, 1 );
First We need to exclude the jquery file in defer parsing because the jquery file is required to load before content loads.
In the latest WordPress, we need to exclude jquery.min.js and in older WordPress, we need to exclude jquery.js.
There is no other effect on site after adding this code.
After add this code you can check the speed and it’s definitely changed.