• Resolved esyagentur

    (@esyagentur)


    Hey there,

    how can prevent css and js from render blocking?

    ###
    material-components-web.min.js
    cf7-material-design.js
    ###
    cf7-material-design.css?

    Please advise.

    Thanks a lot

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author GusRuss89

    (@gusruss89)

    Hi @esyagentur

    All the JavaScript is loaded in the footer, so it won’t block the rendering of any of your page content. You could still defer it with a plugin like Autoptimize if you like, which also allows you to defer all your CSS except for above-the-fold styles.

    Thanks,
    Angus

    Thread Starter esyagentur

    (@esyagentur)

    Hi Gus,

    thanks for support.

    There is only one CSS part blocking rendering – css/cf7-material-design.css
    We only use cf7 on two pages, so we load js and css only on those pages. Can you provide code snippet similar to the following snippet for function.php?

    ?php
    if ( function_exists( ‘wpcf7_enqueue_scripts’ ) ) {
    wpcf7_enqueue_scripts();
    }

    if ( function_exists( ‘wpcf7_enqueue_styles’ ) ) {
    wpcf7_enqueue_styles();
    }
    ?>

    Thanks again.

    Plugin Author GusRuss89

    (@gusruss89)

    Hi @esyagentur

    Try this in your functions.php. It will dequeue all the plugin scripts and styles except on pages with slug ‘contact’ or ‘form’. Change the if condition to suit your pages.

    
    function my_dequeue_cf7md_assets() {
        if( ! is_page( 'contact' ) && ! is_page( 'form' ) ) {
            wp_dequeue_script( 'md-components-js' );
            wp_dequeue_script( 'autosize' );
            wp_dequeue_script( 'cf7-material-design' );
            wp_dequeue_style( 'cf7md_roboto' );
            wp_dequeue_style( 'cf7-material-design' );
        }
    }
    add_action( 'wp_enqueue_scripts', 'my_dequeue_cf7md_assets', 20 );
    

    Thanks,
    Angus

    Thread Starter esyagentur

    (@esyagentur)

    Awesome – works perfect.
    Thanks a lot.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Above the fold blocking’ is closed to new replies.