Iubenda logo
Start generating

Documentation

Table of Contents

How to solve common Cookie Solution issues with cache plugins and optimization features

In some cases, when iubenda’s inline JavaScript is delayed due to:

  • External JavaScript is loaded, and that relies on inline JavaScript.
  • JavaScript minification is active, which saves files locally.
  • Default exclusions are in place.

This could occur specifically when a feature called “JS Optimizations” is configured in cache plugins. Like for example: WP-Rocket, Autoptimize, and similar.

Since our Cookie Solution is written in JavaScript, if other plugins try to optimize it, sometimes our script gets broken – so you should configure each cache plugin so that it “ignores” our “inline” script, which refers to the part that the user pastes into the <head> tag when installing our Cookie Solution or use our plugin.

For example, in the case where the default exclusions are in place, a JavaScript error pops up:

How to avoid the delay of JavaScript execution with iubenda’s default exclusions?

WP-Rocket plug-in

In this case, you just need to do the following:

1. exclude _iub from the “combine” and “minification” feature in the WP-Rocket settings, to do so, add it in the exclusion field, as shown below:

Since our script was broken due to previous JS Optimization, now we need to re-add the original Cookie Solution script in the <head> tag (as the first element) or in our all-in-One WordPress plugin:

Note

If you use WP-Rocket from version 3.13 and the “Delay JavaScript execution” feature is enabled, you can exclude our plugin from the “One-click exclusion” area by selecting our plugin in this way:

exclude plugin one click

2. Re-add the original Cookie Solution script in the <head> section as the first element:

<script type="text/javascript">
var _iub = _iub || [];
_iub.csConfiguration = {"enableCcpa":true,"countryDetection":true,"askConsentAtCookiePolicyUpdate":true,"consentOnScroll":false,"consentOnDocument":true,"ccpaAcknowledgeOnDisplay":false,"whitelabel":false,"lang":"en","siteId":1264045,"cookiePolicyId":93663998, "banner":{ "position":"bottom" }};
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/ccpa/stub.js"></script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>

3. make sure the default exclusions are in place;

4. and check the JavaScript console for the error.

Autoptimize plug-in

This same problem can happen when you are using the Autoptimize plugin and you can solve it by adding only the attribute data-noptimize to our inline Cookie Solution script.

Autoptimize recognises a script attribute, data-noptimize, which means the inline script won’t be inlined or anyway it should be ignore by autoptimize and many users add it in our inline script in this way:

<script data-noptimize="true">
var _iub = _iub || [];
_iub.csConfiguration = {"enableCcpa":true,"countryDetection":true,"askConsentAtCookiePolicyUpdate":true,"consentOnScroll":false,"consentOnDocument":true,"ccpaAcknowledgeOnDisplay":false,"whitelabel":false,"lang":"en","siteId":1264045,"cookiePolicyId":93663998, "banner":{ "position":"bottom" }};
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/ccpa/stub.js"></script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>

Doing these steps, the expected behaviour is that there should be no errors when JavaScript Execution Delay is active.

Note

In general also consider to exclude from every JS Optimization feature of your cache plugin also our external file iubenda_cs.js, stub-v2.js and stub.js

See also