WP Rocket is a caching plugins that helps speeding up your WordPress website.
If you use another plugin for this purpose please see here:
Depending on the WP Rocket Settings you choose it might interfere with the cookie banner. You recognize this by “weird” behavior of the banner, e.g. loading very late or no loading always.
In order to fix that, you need to exclude the beautiful cookie banner script from being optimized with WP Rocket. If you are uncertain if WP Rocket is causing this behavior you can add ?NOWPROCKET=1 to the URL. This disables WP Rocket Plugin.
Steps to exclude beautiful cookie banner from WP Rocket plugin
Step 1: In your WP Admin Dashboard navigate to Settings > WP Rocket
Step 2: Click the “File Optimization” tab and go to the Javascript Files section.
Step 3: In the “JavaScript Files” section, you’ll find minimizing JavaScript files, deferring JavaScript loading, and delaying JavaScript execution. When you activate any of these options, a text field labeled “Exclude JavaScript Files” will appear.
Step 4: For each selected option paste
/wp-content/plugins/beautiful-and-responsive-cookie-consent-addon/(.*)
/wp-content/plugins/beautiful-and-responsive-cookie-consent/(.*)
into the text field labeled “Exclude JavaScript Files”. This will exclude the JavaScript files from being optimized.
Reminder: Those scripts need to be excluded from ALL JavaScript optimisations, e.g. deferred, minimizing or any other available option.
Step 5: Go to “Combine JavaScript files” and add in the Excluded Inline JavaScript field the following:
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
Step 6: Add Cookie Banner CSS to safelist
If you have enabled the “remove unused CSS” in WP-Rocket, see here https://docs.wp-rocket.me/article/1529-remove-unused-css#css-safelist, add this ID to the safelist to exclude it from optimizing:
nsc_bar_nice-cookie-consent-css
nsc_bar_nice-cookie-consent-inline-css
cc-main
cm__body
Step 7: Now save your changes. There shouldn’t be any issues now with your cookie banner. If you still have any issues please check the WP Rocket documentation: https://docs.wp-rocket.me/category/1231-file-optimization or contact support.