Web component / unpkg

<pull-to-refresh>

Load the component from unpkg.

Automatic registration

<script type="module">
import { definePullToRefresh } from 'https://unpkg.com/@aarongustafson/pull-to-refresh@latest/define.js?module';

definePullToRefresh();

document.addEventListener('ptr:refresh', (event) => {
  setTimeout(() => event.detail.complete(), 750);
});

document.addEventListener('submit', (event) => {
  if (!event.target.matches('[data-refresh]')) return;
  const component = document.querySelector('pull-to-refresh');
  if (typeof component?.triggerRefresh !== 'function') return;
  event.preventDefault();
  if (!component.isRefreshing) component.triggerRefresh();
});
</script>
<pull-to-refresh>
  <p>Pull down to refresh this content.</p>
</pull-to-refresh>
<form data-refresh>
  <button type="submit">Refresh</button>
</form>

unpkg CDN sanity check

This page loads the guarded definition helper from unpkg and registers the element when supported.

Pull down to trigger the refresh event. The handler completes after a short timeout.

If the CDN or JavaScript is unavailable, Refresh reloads the document. Content remains available.