Try Now

How to Delay JS until user interaction

In this guide we will help you configure SpeedyCache to Delay JS in your WordPress site.

When a user visits your WordPress website, their browser starts rendering the page's HTML content. As the browser encounters JavaScript files, it pauses the rendering process to fetch and parse each script. This can significantly slow down the overall page load time, especially if you have multiple JavaScript files or heavy third-party scripts like Google Adsense or Google Analytics.

By deferring the parsing of JavaScript, you can instruct the browser to delay the downloading and execution of these scripts until after the HTML content has finished loading. This allows the user to see and interact with the page's main content faster, improving the overall user experience. Additionally, deferring JavaScript can positively impact various performance metrics, such as Largest Contentful Paint (LCP) and Total Blocking Time (TBT), which are crucial for SEO and website rankings.

Delay JS

To delay JS in your WordPress site follow these steps:-

  • In your WordPress admin go to SpeedyCache  -> Settings.
  • Once Inside settings look for Delay JS option and enable it.
Enable Delay JS in SpeedyCache
  • You will see a popup, there you will have to choose if you want to delay selected scripts or all scripts.
  • Delaying all Scripts is an aggressive option but it can break your site too because it may delay a script on which rendering of your website is dependent on.
  • If you select Delay Selected, then you will need to add the scripts you want to delay as it will delay only specific scripts only.
Delay Selected JS in your WordPress site
  • If you select Delay All then you can test the changes in test mode and then exclude the scripts which are causing any issue in normal rendering of your website.
Delay All Scripts of your WordPress website

Note: Do not combine scripts when using Delay All JS because it will break the normal functioning of your website.

Using Delay JS will also affect the analytics if you choose to delay the Analytics Script as it wont count bots or users who don't interact with your website. But it wont affect crawlers from crawling your website.

The events on which the scripts get loaded are listed below:-

  • Mouse Over
  • Click
  • Key Down
  • Wheel
  • Touch Move
  • Touch Start

If you face any issue you can contact our support team support@speedycache.com

    Was this page helpful?
    Newsletter Subscription
    Subscribing you to the mailing list