Skip to content

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:

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:

MethodPurpose
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:

Infinite Scroll Pattern

  1. Render new article markup (including <EzoicAdSlot slotId={...} />).
  2. Call window.__ezoicDynamic.show(newIds) to display the ads.
  3. 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