Ezoic Dynamic Content
How to refresh, add, or destroy Ezoic ad placeholders when Astro pages update dynamically.
Why Dynamic Handling Matters
Ezoic requires you to re-run its ad loader whenever a page changes without a full reload (SPA navigation, infinite scroll, accordions, etc.). The onboarding guide explains that you must call:
ezstandalone.showAds()to render placeholders that appear later,ezstandalone.destroyPlaceholders(...)ordestroyAll()to remove placeholders that leave the page.
To avoid sprinkling these calls throughout templates, TriposRai.com exposes a small helper you can call from any script.
Global Helper API
When src/layouts/Layout.astro loads, it creates window.__ezoicDynamic with the following methods:
| Method | Purpose |
|---|---|
register(id: number) | Adds a placeholder ID and immediately queues showAds(id). |
show(ids?: number | number[]) | Queues ezstandalone.showAds() for the provided IDs. If omitted, refreshes every registered placeholder. |
destroy(ids: number | number[]) | Queues ezstandalone.destroyPlaceholders() for the provided IDs. |
destroyAll() | Queues ezstandalone.destroyAll(). |
refreshAll() | Shorthand for show() with no arguments. |
The helper maintains a registry of every placeholder that appears on the page, so you can reuse IDs safely.
Inline Example
<script>
window.__ezoicDynamic?.show([115, 116]);
</script>
Custom Events
If you prefer to avoid direct references, dispatch the provided events instead:
window.dispatchEvent(new CustomEvent("tripos:ezoic:show", { detail: { ids: [115] } }))window.dispatchEvent(new CustomEvent("tripos:ezoic:destroy", { detail: { ids: [115] } }))- Passing no
idsto thetripos:ezoic:destroyevent triggersdestroyAll().
Infinite Scroll Pattern
- Render new article markup (including
<EzoicAdSlot slotId={...} />). - Call
window.__ezoicDynamic.show(newIds)to display the ads. - When older content unmounts, call
window.__ezoicDynamic.destroy(oldIds)before removing the DOM nodes.
This mirrors the workflow described in Ezoic’s Dynamic Content guide.
Verification Checklist
-
window.__ezoicDynamicis defined in the browser console. - New placeholders load when calling
window.__ezoicDynamic.show([id]). -
destroy/destroyAllremove ad frames before reusing IDs. - Infinite scroll or SPA navigation triggers
astro:page-load(handled automatically by the layout).