• I added this code (there may be a line or 2 of extra code in here that doesn’t pertain to the question)

    add_filter( 'wp_image_editors', 'change_graphic_lib' );
    
    function change_graphic_lib($array) {
    return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    }
    
    function defer_parsing_of_js ( $url ) {
    
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    
    return "$url' defer ";
    
    }
    
    add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );

    My page speed increased on GT Metrix from a 90 to a 97. it loads in about 0.5 seconds.

    The problem:

    This code does not seem to effect all the posts on my blog. Some are super fast, others are not.

    So I came across this code
    I got it from here (I forgot where I got the first code from, sorry to the coder)

    https://varvy.com/pagespeed/defer-loading-javascript.html
    
    add_filter( 'wp_image_editors', 'change_graphic_lib' );
    
    function change_graphic_lib($array) {
    return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
    }
    
    function defer_parsing_of_js ( $url ) {
    
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    
    return "$url' defer ";
    
    }
    
    add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );

    Will this even work, it says it is for html. And will it apply to all pages.

    Another think that may or may not matter.
    I put the first code in my child theme. If I put it in the real place would it work

    My problem is that I have a landing page on my blog that is a slow loader. It loads at fastest 2.5 seconds and at slowest 5.5 seconds.

    No one, including me, is going to wait 5.5 seconds if they are browsing. if they know the content is good they might, but for those just cruising around the web, they are going to leave.

    this is my blog
    https://ragingalcoholic.com

    Can someone tell me how to get these other pages to speed up.

    The javascript parsing is always the number one reason that GT Metrix says makes some of my pages load slowly.

    Thanks

    and again, my apologies to the coder who didn’t get cited properly

    also:
    I have no idea how any of that code works or anything else. My abilities stop after I find the file and cut and paste the code into it. I don’t actually understand what I am doing. I just follow directions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • What are you trying to do? Just speed up loading? What is the url of the landing page?

    Rename wp-spamshield to wp-spamshied-old.
    Turn off auto-optimize. They are causing javascript errors.

    When you post code, highlight it and hit the code button above.

    Thread Starter lucabrasi40

    (@lucabrasi40)

    Yes I am just trying to speed up page load times.

    I will go do as you directed and report back in a minute.

    Thanks for responding.

    This is the landing page:
    https://ragingalcoholic.com/go/get-addiction-treatment-now

    That speeded me up to 2.3 seconds
    It also slowed down my normal blog homepage load by over a second, so it is now 1.5.

    That still doesn’t mean that what we are doing is wrong, it just means there are alot of variables.

    Will renaming the spamshield stop it from working. And do I do that through the cPanel.

    Would deactivating it do the same thing.
    I would even be willing to not have comments and therefore have no need for a spamshield.

    You can check this out but your site looks pretty good.

    https://tools.pingdom.com/#!/9o9DD/https://ragingalcoholic.com

    Thread Starter lucabrasi40

    (@lucabrasi40)

    How do I get the code to work on each page/post of my blog?

    GT Metrix loves that code on the homepage but gives it an F on internal pages.
    (not all internal pages, some have decent grades but all the internal page scored are inferior to the index page)

    Have I put it in the wrong place?
    …….
    If I am using a plugin and I have pasted the code could that be the problem?
    I use Autoptimize, I looked at the settings and it does not say anything about deferring js but it does optimize js. It is also possible that I don’t understand what I am reading.
    Anyway, could that be causing it to not be as effective on internal pages/posts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘defer parsing javascript’ is closed to new replies.