How to exclude Beautiful Cookie Banner from WP Rocket

WP Rocket is a caching and optimization plugin that speeds up WordPress sites. Some of its file optimizations can interfere with the cookie banner. This page lists the WP Rocket settings that matter and the exclusions to add. For other optimization plugins, see problems with speed optimizer and caching plugins.

Which WP Rocket settings affect the banner

You notice a conflict by “weird” behaviour: the banner loads very late, not on every page, without styles, or consent signals arrive after your tags. These settings can cause it:

WP Rocket settingEffect on the bannerFix
Minify / combine JavaScript filesBanner and consent scripts are merged and their order can changeSteps 3–5
Load JavaScript deferredThe consent default runs after your tagsStep 4
Delay JavaScript executionThe banner only appears after the first scroll or clickStep 4
Remove unused CSSThe banner’s styles are removed, the banner is unstyled or invisibleStep 6
Page cacheChanged banner settings show up only after the cache is clearedStep 7

Check whether WP Rocket causes the problem

Add this to the URL of the page:

?wpr_imagedimensions=1&nowprocket=1&no_optimize=1

It disables WP Rocket for this one page load. If the banner works now, continue with the steps below.

Step 1: in your WordPress admin, go to Settings > WP Rocket.

WordPress admin menu with Settings > WP Rocket.

Step 2: open the File Optimization tab and go to the JavaScript Files section.

WP Rocket File Optimization tab with the JavaScript Files section.

Step 3: the JavaScript Files section contains minifying JavaScript, loading JavaScript deferred and delaying JavaScript execution. When you activate one of them, a field Excluded JavaScript Files appears.

WP Rocket JavaScript options with the field for excluded JavaScript files.

Step 4: for each active option, paste this into its exclusion field:

/wp-content/plugins/beautiful-and-responsive-cookie-consent-addon/(.*)
/wp-content/plugins/beautiful-and-responsive-cookie-consent/(.*)

Reminder: these scripts need to be excluded from all JavaScript optimizations: minify, defer, delay and any other option you use.

Step 5: if your WP Rocket version shows Combine JavaScript files, add the following to its Excluded Inline JavaScript field:

nsc_bara_blocking_scripts_inline
nsc_bara_blocking_scripts
nsc_bara_consent_mode_default_script
nsc_bara_consent_mode_update_script
nsc_bar_get_dataLayer_banner_init_script
nsc_bar_nice-cookie-consent_js
nsc_bara_gtm_loader_js-js-before
nsc_bara_gtm_loader_js-js

Step 6: if you have enabled Remove unused CSS (tab File Optimization, section CSS Files), add these entries to the CSS safelist:

nsc_bar_nice-cookie-consent-css
nsc_bar_nice-cookie-consent-inline-css
cc-main
cm__body
/wp-content/plugins/beautiful-and-responsive-cookie-consent-addon/public/css/(.*).css
/wp-content/plugins/beautiful-and-responsive-cookie-consent/public/(.*).css

Step 7: save the settings and clear the WP Rocket cache. Test in a private browser window.

If you still have problems, see the WP Rocket file optimization documentation, the troubleshooting page, or contact support.