Web component / unpkg

<lazy-img>

README · All demos

Guarded registration helper

This page loads the guarded definition helper from unpkg and registers the element when supported. Importing the helper also calls it; the explicit call is safe to repeat. Without JavaScript, or if the module can’t load, the optional image isn’t created; its recovery link remains available. Keep essential images native.

<script type="module">
import { defineLazyImg } from
  'https://unpkg.com/@aarongustafson/lazy-img@latest/define.js?module';
defineLazyImg();
</script>

<lazy-img src="./sample.svg"
  alt="Mountain trail at sunrise illustration">
</lazy-img>
<p>If the optional image is unavailable,
  <a href="./sample.svg">open an alternative image</a>.
</p>

If the optional image is unavailable, open an alternative image.