In this article
What does it do?
This optimization will improve the following recommendations in PageSpeed:
- Minimize Main thread work
- Total blocking time
- Time to Interactive
- First contentful paint
And may improve other Core Web Vitals as well.
You will find it on the File Optimization tab:
How does it work?
- This optimization is applied only on cached or optimized pages.
- It is enabled by default when you first install and activate WP Rocket
- Combine JS will be disabled when using this option, to ensure scripts are loaded in the correct order
- All scripts that are present in the HTML of the page, will be delayed. Any scripts which are inserted after the page loads, or fetched indirectly from another script, cannot be delayed.
Updating to WP Rocket 3.9 from previous versions / New installations of WP Rocket
The previous version of this option relied on an inclusion list, that is, you added the scripts you wanted to delay. From version 3.9 the logic is reversed. So, when updating from 3.7 or 3.8 with Delay JS enabled, or when you enable the feature in WP Rocket 220.127.116.11 or later, everything will be delayed by default and only desired exclusions will need to be entered. This provides the best results for performance.
To quickly resolve issues remove any existing exclusions, add the default exclusions, and check if the issue is resolved:
(?:wp-content|wp-includes)(.*) /jquery-?[0-9.](.*)(.min|.slim|.slim.min)?.js js-(before|after)
Exclude all inline scripts
If you need to troubleshoot inline scripts, you can exclude them all by adding the following to the exclusions field:
To target specific scripts to exclude, choose a unique keyword or string of text from either the filename or script you need to exclude and enter it in the exclusion field.
To identify the original file URLs, make sure that you are looking at the uncached version of the page.
Excluding a file
To specify only this file, the following will work:
Removing the version number is recommended so that the file will still be excluded if it changes.
Excluding multiple files
Excluding multiple files can be done in one of two ways. To exclude all files under
/gravityforms/js/, use either of the following:
1. The exclusion method detects keywords, not just filepaths, so the simplest method is to use:
2. Wildcards can also be used:
Excluding an inline script
To exclude an inline script, choose a string of text that is unique to that script.
In this example,
/woocommerce-no-js/ is a good choice, since it should be specific to this script.
Excluding an external script
To exclude an external script, choose the file name rather than the domain name.
In this example,
/ad-manager.min.js is the string to target.
In this example, targeting
hb.vntsm.com won't work.
If your theme/plugin/service isn't listed there our article will help you identify the specific error and can point out what needs to be excluded.
Lazyload for Images
Some themes provide their own version of the lazyload feature for images. Or you may be using a 3rd-party plugin to apply lazyload.
In such cases, we recommend disabling the theme's/3rd-party plugin's lazy load feature and use WP Rocket's lazyload instead.
We automatically exclude Smush and EWWW's lazyload features. If you are using either of these plugins, you don't need to disable their lazyload.
Preloaders are a feature some themes/plugins offer to hide the content of a page until that's fully rendered - usually, a spinner/loader icon is displayed.
This is also better for the user experience since visitors will be able to see a page's content earlier.
How to check if delaying is working
- This feature is not compatible with IE 11. Visitors using IE11 will be redirected to an uncached version of the page, with the query string ?nowprocket=1 appended to the URL.
Those URLs will appear to the site's analytics. You can read more about this in our doc.
type="rocketlazyloadscript"attribute will be added. This fake type value prevents the script from being executed by the browser.
- If a script already has a type value, it will be copied in a
data-rocket-typeattribute to be preserved
- The delay script adds a preload for all scripts with a
srcattribute, to make sure they are ready for the user interaction.
- On user interaction, our delay script either removes the fake type, or replaces it with the original one, and the browser executes all scripts.
- The delay script is built to preserve the order and priority of the scripts on the page, taking into account attributes like
- As we discover conflicts we will maintain a list of automatic exclusions.
- keydown: event is fired when a key is pressed.
- mouseover: event is fired at document (page) when a pointing device (such as a mouse or trackpad) is used to move the cursor onto it.
- touchmove: event is fired when one or more touch points are moved along the touch surface.
- touchstart: event is fired when one or more touch points are placed on the touch surface.