Exclude scripts from Delay JavaScript Execution only at some URLs

This helper will allow you to exclude JavaScript files from Delay JavaScript Execution option only on specific pages instead of excluding them globally.

This can be useful in some cases where you can delay JavaScript files globally, but you need to exclude some scripts from being delayed only on some pages.

For example, when you have a slideshow on 2 or 3 pages, a modal on one page, etc.

๐Ÿ“ Manual code edit required before use!

๐Ÿ“ฅ   Download (.zip): WP Rocket | Exclude JS scripts from Delay JS only at some URLs
Developers: You can find the code for this plugin on GitHub.

  1. Download the helper plugin zip file, then un-zip it.
  2. Open the PHP file in a text editor.
  3. Edit line 35, change the slugs ("first-slug") to the pages where you want to apply the exclusions only. These are the URLs where the scripts won't be delayed. You can add more slugs as needed. Per example, if you need to apply this on https://www.example.com/my-awesome-page , only use my-awesome-page like the following:
    $excluded_slugs = array( 
                'my-awesome-page',
                //'another-slug', 
               // 'another-one', 
            );
  4. On line 62, add the scripts that need to be excluded from Delay JavaScript Execution ONLY on the above URLs. To add multiple scripts you can duplicate these lines as many times as needed.
  5. Re-zip the folder.
  6. Install the helper plugin on your site - go to Plugins > Add New > Upload plugin and select the zip file.
  7. Activate the plugin.
  8. Clear the WP Rocket cache

Bonus tip

If you need to exclude scripts based on different rules, you can replace lines 41 and 42 with different conditionals, or add more conditions as needed, for example:

// Exclude scripts at the front page
 is_front_page() 

// Exclude scripts at categories
 is_category()

More information on WordPress conditional tags here: WordPress Conditional Tags

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.