Title: Ajax load
Last modified: September 21, 2026

---

# Ajax load

 *  Resolved [efrap](https://wordpress.org/support/users/efrap/)
 * (@efrap)
 * [1 week, 2 days ago](https://wordpress.org/support/topic/ajax-load-5/)
 * This is a very good plugin. I also use the excellent Meta Field block.
 * When using ajax to load youtube blocks, videos will no longer load on click. 
   Any insight on what could be done?
 * I am using a shortcode for generating block with better_youtube_embed_block_render_block()
 * Videos are displayed in query block. Works initially, but when using ajax pagination,
   videos will no longer load on click.
 * Thanks

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Phi Phan](https://wordpress.org/support/users/mr2p/)
 * (@mr2p)
 * [1 week, 1 day ago](https://wordpress.org/support/topic/ajax-load-5/#post-19025771)
 * Hi [@efrap](https://wordpress.org/support/users/efrap/),
 * Thanks for reporting this. I will look into it soon.
 * Best, Phi.
 *  Plugin Author [Phi Phan](https://wordpress.org/support/users/mr2p/)
 * (@mr2p)
 * [1 week ago](https://wordpress.org/support/topic/ajax-load-5/#post-19026777)
 * Hi [@efrap](https://wordpress.org/support/users/efrap/),
 * I’ve just fixed this issue in the latest version 1.1.7. Please upgrade the plugin
   to get the fix.
 * Thanks again fo reporting it!
 * Best, Phi.
 *  Thread Starter [efrap](https://wordpress.org/support/users/efrap/)
 * (@efrap)
 * [6 days, 4 hours ago](https://wordpress.org/support/topic/ajax-load-5/#post-19028722)
 * This is great, works perfect. Thank you!
 * Your plugins are really useful. Looking forward to try Content Blocks Builder.
 *  Plugin Author [Phi Phan](https://wordpress.org/support/users/mr2p/)
 * (@mr2p)
 * [5 days, 23 hours ago](https://wordpress.org/support/topic/ajax-load-5/#post-19028833)
 * [@efrap](https://wordpress.org/support/users/efrap/) You’re very welcome! I’m
   glad to hear that it works. I hope you enjoy [Content Blocks Builder](https://wordpress.org/plugins/content-blocks-builder/)
   too!
 * Phi.
 *  Thread Starter [efrap](https://wordpress.org/support/users/efrap/)
 * (@efrap)
 * [5 days, 6 hours ago](https://wordpress.org/support/topic/ajax-load-5/#post-19029515)
 * I thought the fix was working, but it isn’t. I had worked on some js code that
   finally fixed it. It was probably still in browser cache when I tested your latest
   version.
 * I used an LLM to help, since this is way out of my league.
 * The plugin’s `frontend.js` (loaded as `boldblocks-youtube-block-view-script-js`)
   is an IIFE that runs **once** on page load. It scans the DOM for `[data-video-
   id]` elements and initializes each one into a playable YouTube block. When AJAX
   pagination (Query Loop, etc.) injects new posts into the DOM **after** that initial
   scan, the new YouTube blocks are never initialized — they stay as inert thumbnails.
 * A standalone script that watches for new YouTube blocks being added to the DOM
   and **re-injects `frontend.js`** so its IIFE re-runs and picks up the newcomers:
    1. **Grab the original script URL** from the existing `<script id="boldblocks-youtube-
       block-view-script-js">` tag, preserving WordPress’s `?ver=` cache-buster.
    2. **Watch the DOM** with a `MutationObserver` for any newly-added element matching`[
       data-video-id]:not([data-byeb-ready])`, or containing one.
    3. **When new blocks appear**, remove any previous re-injection (`#byeb-reinit`)
       and append a fresh `<script>` pointing at the same URL with `&reinit=<timestamp
       >` to defeat caching. Preserve `defer` and `data-wp-strategy="defer"` so loading
       semantics match the original.
    4. **Debounce** with `requestAnimationFrame` so a batch of mutations (e.g., 10 
       posts inserted at once) triggers only one re-injection per frame.
    5. **No jQuery, no event hooks** — the observer alone covers AJAX pagination, `
       fetch()`-driven loads, and any other DOM-insertion path.
 * 
   Here is the js code:
 *     ```wp-block-code
       (function() {var SCRIPT_URL = null;var scheduled = false;function getScriptUrl() {    if (SCRIPT_URL) return SCRIPT_URL;    var original = document.getElementById('boldblocks-youtube-block-view-script-js');    if (original && original.src) SCRIPT_URL = original.src;    return SCRIPT_URL;}function reinit() {    // Coalesce multiple rapid mutations into a single re-injection per frame    if (scheduled) return;    scheduled = true;    requestAnimationFrame(function() {        scheduled = false;        var url = getScriptUrl();        if (!url) return;        var old = document.getElementById('byeb-reinit');        if (old) old.remove();        var s = document.createElement('script');        s.id = 'byeb-reinit';        s.src = url + '&reinit=' + Date.now();        s.defer = true;        s.setAttribute('data-wp-strategy', 'defer');        document.body.appendChild(s);    });}new MutationObserver(function(mutations) {    for (var i = 0; i < mutations.length; i++) {        var nodes = mutations[i].addedNodes;        for (var j = 0; j < nodes.length; j++) {            var n = nodes[j];            if (n.nodeType !== 1) continue;            if (                (n.matches && n.matches('[data-video-id]:not([data-byeb-ready])')) ||                (n.querySelector && n.querySelector('[data-video-id]:not([data-byeb-ready])'))            ) {                reinit();                return;            }        }    }}).observe(document.body, { childList: true, subtree: true });})();
       ```
   
 *  Plugin Author [Phi Phan](https://wordpress.org/support/users/mr2p/)
 * (@mr2p)
 * [4 days, 23 hours ago](https://wordpress.org/support/topic/ajax-load-5/#post-19029746)
 * Hi [@efrap](https://wordpress.org/support/users/efrap/),
 * Thanks for sharing the code. Could you please provide me with the steps to reproduce
   this issue? A link to your site would be helpful as well.
 * Thanks, Phi.
 *  Plugin Author [Phi Phan](https://wordpress.org/support/users/mr2p/)
 * (@mr2p)
 * [2 days, 9 hours ago](https://wordpress.org/support/topic/ajax-load-5/#post-19031335)
 * Hi [@efrap](https://wordpress.org/support/users/efrap/),
 * Based on my test with WordPress 7.1.2 and 2025 theme, everything works as expected.
   It would be very helpful if you could share more details about your setup so 
   I can reproduce this issue.
 * Thanks, Phi.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fajax-load-5%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/better-youtube-embed-block/assets/icon.svg?rev=3523945)
 * [Embed YouTube Block - Fast Loading Videos, Shorts & Playlists](https://wordpress.org/plugins/better-youtube-embed-block/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/better-youtube-embed-block/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/better-youtube-embed-block/)
 * [Active Topics](https://wordpress.org/support/plugin/better-youtube-embed-block/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/better-youtube-embed-block/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/better-youtube-embed-block/reviews/)

 * 7 replies
 * 2 participants
 * Last reply from: [Phi Phan](https://wordpress.org/support/users/mr2p/)
 * Last activity: [2 days, 9 hours ago](https://wordpress.org/support/topic/ajax-load-5/#post-19031335)
 * Status: resolved