Skip to content

Instantly share code, notes, and snippets.

@johndwells
Last active January 26, 2024 18:08
Show Gist options
  • Save johndwells/f121297d0999c52dfa775b3daf5232cd to your computer and use it in GitHub Desktop.
Save johndwells/f121297d0999c52dfa775b3daf5232cd to your computer and use it in GitHub Desktop.
Lazyload DOM fragment with AlpineJS + Unpoly
<div up-id="replace-me-lazy">
Hello, world!
</div>
<!-- onload, will be replaced with contents from `/fragment` -->
<div up-id="replace-me-lazy"
x-data
x-init="up.render({ target: '[up-id=replace-me-lazy]', url: '/fragment' })">
<!-- placeholder content can go here -->
</div>
@johndwells
Copy link
Author

Ensure that a DOM element with up-id="replace-me-lazy" is present in both the initial page response, and the fragment response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment