How to make otblock.js from one trust load before a specific clientlib? | Community
Skip to main content
Level 4
April 30, 2026
Question

How to make otblock.js from one trust load before a specific clientlib?

  • April 30, 2026
  • 1 reply
  • 8 views

How to make otblock.js from one trust load before a clientlib based on a specific condition ?

    1 reply

    VeenaVikraman
    Community Advisor
    Community Advisor
    April 30, 2026

    Hi ​@ChinmayiSh 

    otblock.js from OneTrust is usually loaded from a CDN, not as an AEM clientlib. Because of that, things like dependencies or embed won’t reliably control the order. The safest way is to control it in HTL, where you define the actual HTML output.

    What you should do

     

    Load OneTrust first, then your clientlib.. Browser reads scripts top to bottom. So if OneTrust is above, it will always load first. That is the only reliable control you have for external scripts.

    <!-- customheaderlibs.html -->

    <sly data-sly-use.page="com.yourpackage.PageModel">

    <sly data-sly-test="${page.oneTrustRequired}">
    <script
    src="https://cdn.cookielaw.org/consent/XXXX/otBlock.js"
    type="text/javascript"
    charset="UTF-8"
    data-domain-script="XXXX">
    </script>
    </sly>

    <sly data-sly-call="${clientlib.js @ categories='your.clientlib.category'}"/>

    </sly>

     

    One more important thing, your JS should also wait for consent. Something like 

    function OptanonWrapper() {
    initApp();
    }

     

    or 

    window.addEventListener('OneTrustGroupsUpdated', initApp);

    Hope this helps

     

    Thanks

    Veena