Load JavaScript deferred

In this Article

What does Load JavaScript Deferred do?

This option addresses the PageSpeed recommendation:

“Eliminate render-blocking resources”

It is preferable for performance that JavaScript files are either loaded in the footer of your site, or deferred so that they don’t block the downloading of other assets on your site, thereby slowing it down. 

By enabling Load JavaScript deferred, all the JavaScript files on your page, including those minified by WP Rocket, will be loaded with the defer attribute:

If you have any issues on your site after activating this option, you may need to activate Safe Mode, which excludes jQuery from being deferred, for compatibility reasons:

Depending on your site, you may also need to exclude some more files from being deferred:  
Exclude files from Defer JS

Note that Google does not take into consideration that sometimes it’s not possible to defer all JavaScript—at least not without breaking your site. Any files you exclude from deferring will cause PageSpeed to complain, however those notices are “false positives”. If your site requires render-blocking jQuery to function correctly, disabling Safe Mode may make the PageSpeed notice disappear, but it will break functionality on your site.

Files that will not have defer applied

The defer attribute will not be applied to elements that already have either of the following attributes:

  • async
  • data-cfasync="false"

GT Metrix - Defer parsing of JavaScript

When you run a GT Metrix test you may find that it doesn't give you a perfect score for this recommendation, even when Load JavaScript Deferred is activated. Here are the most common reasons. To see if this applies to your site, make sure you click on the recommendation to reveal the list of files.

Files excluded for compatibility

  • jquery.js
    If you have enabled Safe Mode, jQuery.js is excluded to prevent issues on your site. You can try disabling Safe Mode, but make sure you check your site carefully while logged out of WordPress, to make sure everything is working as expected on your site.

  • https://www.google.com/recaptcha/api.js
    We automatically exclude this Google Recaptcha file to prevent an issue. 
  • There are a few other automatic exclusions we make to prevent known issues when deferred. List of excluded files

Files injected by Cloudflare

If you've activated certain options in Cloudflare they will inject some JS files when the page loads. We don't have control over them and they won't be deferred. For example, if you've activated their Email Address Obfuscation feature, you'll find this file listed by GT Metrix:

  • cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js

Files loaded indirectly

Only files that are present in the HTML of the page when it loads will have the defer tag applied to them. In some cases one JS file will create a chain in which it loads yet another JS file which cannot then not be deferred. Common examples:
  • Google Recaptcha files, e.g: https://www.gstatic.com/recaptcha/releases/wk6lx42JIeYmEAQSHndnyT8Q/recaptcha__en.js
  • Youtube files, e.g:
  • https://www.youtube.com/yts/jsbin/www-embed-player-vfl4oVEZe/www-embed-player.js
  • https://www.youtube.com/yts/jsbin/player-vflzQZbt7/en_US/base.js

Files without a .js extension

Files must have a .js extension to be deferred. Common examples of files flagged by GT Metrix, without the .js extension:

  • Google Maps files, e.g. https://maps.googleapis.com/maps/api/js?key=
  • Youtube files, e.g. https://www.youtube.com/embed/KEh_6XMF4jY?feature=oembed
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.