How to Defer Parsing of JavaScript in Breeze


How do I do it in Breeze?
Thanks for any help!


I would also like to know this as GTMetrix gives an F grade of 0 for “Defer parsing of JavaScript” For me, specifically, it’s showing these URLs. I tried adding them to the last setting under the advanced options, but it didn’t seem to help. (955.8KiB) (955.8KiB) (90.3KiB) (90.3KiB) (3.3KiB of inline JavaScript) (3.3KiB of inline JavaScript)


Cloudways’ Breeze plugin for Wordpress does not have a Defer Parsing feature.

So, you will either need add custom code to your functions.php file like this: (Ex: defer everything except jQuery):

// Defer javascripts (except jquery.js)
if (!is_admin()) {
  function defer_parsing_of_js ( $url ) {
    if ( FALSE === strpos( $url, '.js' ) ) return $url;
    if ( strpos( $url, 'jquery.js' ) ) return $url;
    return "$url' defer onload='";
  add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );

Or use a plugin like:

  • Autoptimize
  • Async JavaScript
  • WP Rocket

If you do choose to use a Plugin, you may have to blacklist some plugins/javascript files in order for certain features on your website to load properly. And if you really need a specific plugin to defer loading a javascript file, but doesn’t work if you use the above methods, the plugin’s code will likely need to change so that it will wait to try to use the functions in the javascript file until it has loaded. Meaning, you either need to contact the plugin’s developer or hire someone like me! :slight_smile: to handle this for you.