Skip to main content

Idea: Support for lazy loading of iframes



  • Official comment
    Richard van der Velde

    Hi Adrian,

    Since lazy loading also likes using data-src, you can also use data-cookieblock-src instead.
    Our auto blocker does the same thing, specifically to avoid clashing with lazy loaders.

  • Adrian

    We have managed to implement this by ourselves (thanks cookiebot for nothing).

    By removing the "data-cookieconsent" attribute from the <iframe> tag(s) and then, via Cookiebot's events, we have added an identifier (class name) to the <iframe>s only when the specific Cookie category was accepted. Afterwards, we re-initialized the lazy load functionality. This way, we have implemented consent for YouTube videos while also having them loading only when needed, and not directly after consent is given (which in our case is directly when the page loads, as we use Cookiebot as a Cookie wall -- users cannot continue unless they consent).


    You can find below our approach, for whomever might also be interested in this.

  • Adrian
    // hook on the "CookiebotOnAccept" event
    // (this event triggers when the user accepts the use of cookies, as well as if the user has consented at an earlier visit)

    window.addEventListener('CookiebotOnAccept', function (e) {

    // check if Marketing cookies have been accepted
    if ( {

    // add an identifier to all iframes
    // (which should not have "src" attributes anymore, but "data-src" ones)

    // next, re-initialize your lazy loading script
    // (first, also add {your_identifier} to the list of selectors in your lazy loading script setup)
    }, false);

Please sign in to leave a comment.