Web component / esm.sh

<pull-to-refresh>

Load the component from esm.sh.

Class-only import

<script type="module">
import { PullToRefreshElement } from 'https://esm.sh/@aarongustafson/pull-to-refresh@1.1.3/pull-to-refresh.js?bundle&target=es2022';

if (!customElements.get('pull-to-refresh')) {
  customElements.define('pull-to-refresh', PullToRefreshElement);
}

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>

esm.sh CDN sanity check

This page loads the component class from esm.sh and registers it manually.

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.