Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Hi nasy84!

    Have you thought about using a plugin rather than hard-coding that? A quick Google search shows a good way of going about it:

    https://wpcodesnippet.com/add-async-and-defer-attributes-javascript-elements/

    Hope that helps!

    Thread Starter nasy84

    (@nasy84)

    Thank you Jose ??

    I just added at the bottom of functions.php this code:

    // add async and defer to javascripts
    function wcs_defer_javascripts ( $url ) {
        if ( FALSE === strpos( $url, '.js' ) ) return $url;
        if ( strpos( $url, 'jquery.js' ) ) return $url;
        return "$url' async='async";
    }
    add_filter( 'clean_url', 'wcs_defer_javascripts', 11, 1 );

    But, I don’t see any improvement, when I check, the message is still there, and load speed is the same,

    Recommend please some of plugin…

    [Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to eliminate render-blocking JavaScript and CSS’ is closed to new replies.