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.
- Download the helper plugin zip file, then un-zip it.
- Open the PHP file in a text editor.
- 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 usemy-awesome-page
like the following:
$excluded_slugs = array( 'my-awesome-page', //'another-slug', // 'another-one', );
- 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.
- Re-zip the folder.
- Install the helper plugin on your site - go to Plugins > Add New > Upload plugin and select the zip file.
- Activate the plugin.
- 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