Documentation Index

Fetch the complete documentation index at: https://usercentrics.document360.io/llms.txt

Use this file to discover all available pages before exploring further.

How can I reduce the script size of the Usercentrics bundle?

Prev Next

To improve the performance of the Usercentrics CMP v2, we offer a script that will automatically decide which version of our bundle.js should be used. We recommend changing to that script, our loader.js, for optimal performance of your CMP.

This script is only available for customers using version 2 of our CMP.

Loader.js is the newest version of our CMPv2 script with improved performance. This was achieved by adding code splitting and automatically deciding what version of bundle.js should you use, based on your browser version.

Updating to loader.js

Since the loader.js is an all-new script, it also brings some new changes to our API and to our current script implementation. So you will need to follow these steps to update to the newest loader.js:

  1. Update your current Usercentrics CMP scripts
    The loader.js is a new script, so you will need to change your bundle.js or bundle_legacy.js scripts. Do not worry about legacy browsers. loader.js will automatically decide if it should use bundle.js or bundle_legacy.js based in your browser and in your browser version. These are the new scripts that you should change to:

    • For non-TCF users

      <script id="usercentrics-cmp" data-settings-id="XXXXXXX" src="https://app.usercentrics.eu/browser-ui/latest/loader.js" async></script>

    • For TCF 2.0 users

      <script id="usercentrics-cmp" data-settings-id="XXXXXXX" src="https://app.usercentrics.eu/browser-ui/latest/loader.js" data-tcf-enabled></script>

  2. Adapt your current code
    As you've seen in your consoles inside your pages, there are some functions from our API that are deprecated, so you will need to adapt them to the new versions:

    • getServices should be changed by getServicesBaseInfo or getServicesFullInfo

Why update to this new script

With all the variants inside the same base code, we’re shipping more code and data than necessary for the CMP, that’s why we created this script with code splitting in mind. Code Splitting will split the code to ship only the necessary code based on the variant (TCF, CCPA, Default UI, Legacy Browser, …).

Having this change to the code increases the performance of our CMP and therefore increases the lighthouse performance of your page.

To take advantage of the performance improvements now and in the future we strongly suggest this change.