Support Home > Exclude JavaScript files from Jetpack Boost deferral

Exclude JavaScript files from Jetpack Boost deferral

If you experience unwanted website behavior when you defer JS with Jetpack Boost, the affected functionality could rely on the JavaScript files being in a certain order or being made available to the page as soon as possible.

In such cases, you can tell Jetpack Boost not to defer those specific files by adding the attribute data-jetpack-boost="ignore" to the script tag.

Example (if your script tag is hardcoded):

<script data-jetpack-boost="ignore">

If your script tag is enqueued with wp_enqueue_script like the following:

function wpdemo_enqueue_scripts() {
    wp_enqueue_script( 'wpdemo', get_template_directory_uri().'/js/wpdemo.js' );
}
add_action( 'wp_enqueue_scripts', 'wpdemo_enqueue_scripts' );

You can use the example snippet below and add it to your themes functions.php file:

function add_data_jetpack_boost_tag( $src, $handle ) {
    if ( $handle !== 'wpdemo') {
        return $src;
    }
    return str_replace( ' src', ' data-jetpack-boost="ignore" src', $src );
}
add_filter( 'script_loader_tag', 'add_data_jetpack_boost_tag', 10, 2 );

Remember to replace wpdemo with the handle of the script file you want to exclude.

  • Table Of Contents

  • Contact Us

    Need more help? Feel free to contact us.