How to Exclude Third-Party Scripts in NitroPack and WP Rocket
Overview
When advanced optimization is enabled, performance plugins such as NitroPack and WP Rocket aggressively modify how scripts, styles, and iframes are loaded. While this generally improves performance, some third-party scripts and widgets are built in a way that makes them incompatible with advanced optimization techniques such as deferring, delaying, combining, or lazy-loading.
It is important to understand that the BionicWP support team cannot always know which third-party scripts, widgets, or embeds are being used on your site. These scripts may be added by themes, plugins, custom code, marketing tools, analytics platforms, or external services.
For this reason, BionicWP provides guidance on how to exclude problematic scripts, iframes, or pages from optimization. If exclusions do not resolve the issue, please contact BionicWP support so we can assist further.
Important Consideration
Excluding any script, iframe, or page from optimization means it will load without performance enhancements. As a result, your PageSpeed and Core Web Vitals scores may decrease. Exclusions should only be applied when necessary to restore functionality.
NitroPack: Excluding Scripts and Iframes
NitroPack provides a built-in mechanism to exclude specific scripts and iframes from optimization by using the nitro-exclude attribute. This is especially useful when a third-party widget breaks under advanced optimization.
Excluding a Script Using nitro-exclude
Add the nitro-exclude attribute directly to the script tag:
<script src="https://example.com/widget.js" nitro-exclude></script>This tells NitroPack to skip all optimization for that script.
Excluding an Inline Script
<script nitro-exclude>
// Inline third-party script code
</script>Excluding an Iframe
<iframe src="https://example.com/embed" nitro-exclude></iframe>This is commonly required for embedded widgets such as booking tools, chat widgets, video players, or external forms.
When to Use NitroPack Exclusions
Use nitro-exclude when:
A widget does not load or initialize correctly
A script fails only when advanced optimization is enabled
User interactions (clicks, form submissions, popups) stop working
WP Rocket: Excluding Scripts, Iframes, and Pages
WP Rocket offers multiple exclusion options through its settings panel. These exclusions are applied by URL patterns or file names rather than HTML attributes.
Excluding a JavaScript File
Go to WP Rocket → File Optimization
Locate Excluded JavaScript Files
Add the script URL or a partial match, for example:
example.com/widget.jsThis prevents the script from being deferred, delayed, or minified.
Excluding Inline JavaScript
Go to WP Rocket → File Optimization
Under Excluded Inline JavaScript, add a unique string found inside the inline script, such as:
ThirdPartyWidgetInitWP Rocket will skip optimization for any inline script containing that string.
Excluding an Iframe from Lazy Loading
Go to WP Rocket → Media
Disable lazy loading for iframes globally, or
Add the iframe URL to the exclusion list, for example:
example.com/embedThis ensures the iframe loads normally without delay.
Excluding an Entire Page from Optimization
Go to WP Rocket → Advanced Rules
Under Never Cache URLs, add the page URL or pattern:
/checkout/This is useful for pages that rely heavily on real-time scripts or dynamic content.
Best Practices
Apply exclusions incrementally and test after each change
Exclude only the specific script or iframe causing the issue
Avoid excluding entire pages unless absolutely necessary
Re-test PageSpeed and functionality after applying exclusions
Need Further Help?
If you continue to experience issues after applying the recommended exclusions, please contact BionicWP support. Provide details about the affected page, the third-party script or widget involved, and the optimization plugin in use so we can assist you more effectively.
