top of page

Defer Parsing of Java script in WP

  • Writer: سُلَيْمَان بْن دَاوُوْد
    سُلَيْمَان بْن دَاوُوْد
  • May 29, 2020
  • 1 min read

This is generally useful in speed optimisations and can help a lot to reduce load time of pages specially when your site depend heavily on javascripts.



/*Defer parsing js*/
if ( ! is_admin() ) {
function defer_parsing_of_js ( $url ) {
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' defer='defer";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}
/*End Defer parsing js*/



Recent Posts

See All
Google ReCAPTCHA with AJAX

This is how you can pass on AJAX .js var userdata = { 'action' : 'signin_member', 'username' : jQuery('#user_name').val(), 'password' :...

 
 
 
Self Invoking Function jQuery

The function starts with (function ($) { and you can use your own code inside it (function ($) { jQuery(document).ready(function () {...

 
 
 
Smooth Scroll In JS and jQuery

jQuery(document).ready(function () { jQuery('.processreachfind').click(function(e){ e.preventDefault(); jQuery('html, body').animate({...

 
 
 

Comments


© 2020 by syednazrulhassan

bottom of page