Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #673790

    Hey there,

    i came across these ressources in order to defer javascript.

    1. ressource: https://varvy.com/pagespeed/defer-videos.html
    1. question: My question: where can i put javascript to bottom of a specific page?

    2. ressource: https://varvy.com/pagespeed/defer-images.html
    2. question: My question: where can i put the script before the end body?

    and 3rd:
    Can i use this code:

    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 );

    to defer parsing javascript?

    So in fact its a noob question, but i would appreciate if you can guide me through.
    Thank you very very much!
    tobi

    • This topic was modified 7 years, 8 months ago by Tobiy.
    #675153

    Hey Tobiy,

    1. You can use a Code Block.

    2. You can use the wp_footer hook:

    add_action('wp_footer', function() {
    ?>
    CODE
    <?php
    });

    Best regards,
    Josue

    #675284

    Hey Josue, thank you very much. Let me clarify:
    In order to use code on a specific page, i add a code block at the bottom of a page via page layout builder and add the code?

    Do you mean i type code like thins in function php?

    add_action(‘wp_footer’, function() {
    ?>
    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 );
    <?php
    });

    Thank you very much!

    #675361

    1. Use a code block to insert a code per Page.

    2. The wp_footer code i posted was a response to (that will apply the code to all pages):

    2. question: My question: where can i put the script before the end body?

    3. The JS defer code is already a WordPress filter, paste it as it is in functions.php.

    #675866

    ok this code breaks the site:

    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 );

    and if i enter the code block the code appears on the page.

    So i can just use the code 1. and 2. as you have said? Maybe we have a misunderstanding? I am irritated now…sorry.

    • This reply was modified 7 years, 8 months ago by Tobiy.
    #675878

    Hi,

    Can you create me a WordPress administrator account? i can make a page with each script added so you can take that as a reference.

    Regards,
    Josue

    #675938

    This would be so amazing Josue!

    • This reply was modified 7 years, 8 months ago by Tobiy.
    #676093

    Ok, 2 and 3 are applied site-wide, 1 is on a Page called “Test”.

    Best regards,
    Josue

    #676261

    Josue, you are amazing! Thank you, Thank you, Thank you! Result in gmetrix:PageSpeed Score 100, YSlow Score 98% (argh..google fonts and little stuff, nothing serious). Enfold Team is the best support team ever! Thank you! If anyone else needs help to implement, now i can help too ;-)

    • This reply was modified 7 years, 8 months ago by Tobiy.
    #676820

    You are welcome, glad to help :)

    Regards,
    Josue

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘defer videos and images’ is closed to new replies.