Iubenda logo
Start generating

Documentation

Table of Contents

Cache, Speed and Other Optimization of the iubenda Cookie Solution (legacy)

This article refers to the legacy version of the Cookie Solution. For existing implementations (before 11.03.2019), we strongly suggest upgrading your Cookie Solution by simply copying the new code here (Dashboard > [Your website/app] > Cookie Solution > Embed) to avoid any CSS related conflicts and to access all the new features. If you’ve already updated your code to the new version, please find the updated Guide here.

If you would like to use a specific version of the iubenda cookie solution, you simply need to insert the following link in lieu of the one normally used in the Cookie Solution:

https://cdn.iubenda.com/cookie_solution/versions/0.11.36.4/iubenda_cs.js

The “0.11.36.4” value must be substituted with the number of the version to be used. Available versions are found in the Current and Stable channels, starting with version 0.11.36.4 (consult the complete changelog for a listing of all released Cookie Solution versions).

Unlike the default link, the link mentioned above has a very extended cache configuration as it points to a specific version which does not require future modifications.

By applying the modification described above to the Cookie Solution, the iubenda_cs.js resource will load a new file containing the desired version. It’s a best practice, also adopted by Google for the loading of Google Analytics, as a way to achieve a compromise between the need to update the Cookie Solution and the loading/cacheing speed. The iubenda_cs.js file is in fact a file with a brief cache of few bytes, which in turn calls the real Cookie Solution, whose cache is much more extensive.

Alternatively, you can bypass iubenda_cs.js and directly load the file with the hash of the version and you will be able to:

  • Eliminate an intermediary passage (resulting however in an almost negligible gain of a few milliseconds)
  • Access a version of the file with a very long cache

Direct loading of the Cookie Solution

If Google Lighthouse provided you with a suggestion similar to the following, we can help you solve the problem:

Look through the browser’s cache: If there is a maximum age for statistic resources in the HTTP headers or if an expiry date is set, the browser will load the the resources previously downloaded from the local disk instead of from the network.

To bypass iubenda _cs.js, the first thing to do is get the hash from the desired version. As we saw before, you need to substitute “0.13.20” with the version of the Cookie Solution you wish to activate and visit https://cdn.iubenda.com/cookie_solution/versions/iubenda_cs-0.13.20.js (if you wish to activate the last available option, head directly to the following address).

Copy the content of the parameter e="xyz", which is in fact the version’s hash. For example, if we take version “0.13.20” visiting https://cdn.iubenda.com/cookie_solution/versions/iubenda_cs-0.13.20.js we will have e="79553260f6ee5c2ea30ac8946c4556de".

At this point you can compile the new URL with the hash of the chosen version. To do so, simply substitute the link above with the one normally called in the Cookie Solution code. To create the URL, you can use the following structure:

https://cdn.iubenda.com/cookie_solution/iubenda_cs/core-

+

parameter value “e

+

.js

Using the last version’s hash for example, the result is the following: https://cdn.iubenda.com/cookie_solution/iubenda_cs/core-cd40c5caf396e9e6430490ac6bae6c41.js

Note

If you decide to block the iubenda Cookie Solution at a specific version, we suggest that you manually update it so that you may continue to benefit from our updates.

Direct embedding in the page of the activator

The inclusion of the activator inside the page can only be done in the safemode version of our Cookie Solution.

It’s possible to include the part of the code relative to the scripts, directly in-page (inline); this code is known as the inline activator. Scripts can be activated through the inline activator even if the iubenda_cs.js primary resource is generically unavailable or in error.

Additional information

The inline activator only guaranties script activation but can also take on a provided permission (see the following forceSafeActivation option); it cannot be used to show the banner, the cookie policy or manage the obtaining of consent.

It serves only as another layer of protection in case of errors and does not at all act as a substitute for the main iubenda Cookie Solution code (for additional information on how to set up the Cookie Solution, you can read this article).

Note that the inline activator will only invoke the onActivationDone, while others will be ignored.

Two additional configuration options are available for the inline activator:

  • safeTimeout: (milliseconds, default 5000) – The time required for the inline activator to be triggered (before activating the script the following option will also present itself
  • forceSafeActivation: (boolean, default false) – If true, scripts are activated regardless of consent obtained. If false, the inline activator activates the scripts only if consent has been provided ( and registered in the preference cookie in the page of the host domain)

The inline activation is available at https://cdn.iubenda.com/cookie_solution/safemode/safe.js

Important

The content of this file is to be included in-page after the initial configurations and before the code that loads iubenda_cs.js.

Example

<head>
...

<script type="text/javascript">
    var _iub = _iub || [];
  _iub.csConfiguration = {
    cookiePolicyId: XxX,
    siteId: YyY,
    // other config options...
  };
_iub.csConfiguration.safeTimeout = 2000; // Custom option for Safemode
_iub.csConfiguration.forceSafeActivation = false; // Custom option for Safemode
</script>

<script type="text/javascript">
//<![CDATA[
  //copy content from cdn.iubenda.com/cookie_solution/safemode/safe.js and paste here.
//]]>
</script>

<script type="text/javascript" src="//cdn.iubenda.com/cookie_solution/safemode/iubenda_cs.js" charset="UTF-8" async></script>

...
</head>

Note

The activator code is an integral part of the iubenda Cookie Solution and as such can be modified to include new features, upgrades and fixes.

Releases of new versions of the iubenda Cookie Solution that also include the modification of the inline activator are marked in changelog with the [safe.js updated].

To facilitate the management of the activator version in your page, the _iub.csSafeActivatorVersion variable is available, which recalls the iubenda_cs.js version from which the activator was extracted.

(Optional) Suggested settings for performance optimization

  • startOnDomReady (boolean, default false) – Set to true. Please refer to the documentation here for more details. This setting may need to be tested on a site by site basis as it may not work on all websites.
  • inlineDelay (integer, milliseconds, default 800 (safemode 500)) – By decreasing this value you will reduce the total time of activation.

Important things to know:

  • when startOnDomReady is set to true, the reactivation could cause some issues as snippet activation may occur while some resources are still being loaded.
  • inlineDelay works only with the “-inline” block, so it is reduced only to that kind of snippet. Its default value is 1000, but we recommend to not set under 300. It is highly recommended to check the activation of the snippet shown on your page if this setting is changed.

See also