npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

alpinejs-poll

v1.1.0

Published

Alpine.js plugin for polling and visibility tracking.

Downloads

288

Readme

Alpine JS Poll

Alpine.js plugin for polling and visibility tracking.

What you get

  • x-poll - Execute expressions at intervals
  • x-visible - React to page visibility changes
  • Visibility-aware polling with .visible modifier
  • Supports ms, s, m, h time units

Install

CDN

<script defer src="https://unpkg.com/alpinejs-poll@latest/dist/cdn.min.js"></script>
<script defer src="https://unpkg.com/alpinejs@latest/dist/cdn.min.js"></script>

Package

npm install -D alpinejs-poll
import Alpine from 'alpinejs'
import poll from 'alpinejs-poll'

Alpine.plugin(poll)
Alpine.start()

Usage

x-poll

Execute an expression at regular intervals. Executes immediately on init, then at each interval.

<div x-data="{ count: 0 }" x-poll.1s="count++">
  Count: <span x-text="count"></span>
</div>

Time Units

| Modifier | Description | |----------|-------------| | .500ms | 500 milliseconds | | .1s | 1 second | | .5m | 5 minutes | | .1h | 1 hour |

Default interval is 60 seconds if not specified.

<!-- Poll every 5 seconds -->
<div x-poll.5s="fetchData()">...</div>

<!-- Poll every 100ms -->
<div x-poll.100ms="tick()">...</div>

<!-- Poll every 2 minutes -->
<div x-poll.2m="refresh()">...</div>

x-poll.visible

Only poll when the page is visible. Executes immediately when visibility is restored.

<div x-data="{ data: null }" x-poll.5s.visible="data = await fetchData()">
  <span x-text="data"></span>
</div>

Visibility is tracked via:

  • document.visibilitychange - tab switching
  • window.focus / window.blur - window focus
  • pageshow / pagehide - iOS PWA / bfcache

x-visible

React to page visibility changes. Use $visible to access the visibility state.

<div x-data="{ status: 'visible' }" x-visible="status = $visible ? 'visible' : 'hidden'">
  Status: <span x-text="status"></span>
</div>
<!-- Pause video when tab is hidden -->
<video x-data x-visible="$visible ? $el.play() : $el.pause()">
  <source src="video.mp4" type="video/mp4">
</video>
<!-- Track visibility changes -->
<div x-data="{ count: 0 }" x-visible="count++">
  Visibility changed <span x-text="count"></span> times
</div>

Examples

Auto-refresh data

<div x-data="{ users: [] }" x-poll.30s.visible="users = await (await fetch('/api/users')).json()">
  <template x-for="user in users">
    <div x-text="user.name"></div>
  </template>
</div>

Live clock

<div x-data="{ time: new Date() }" x-poll.1s="time = new Date()">
  <span x-text="time.toLocaleTimeString()"></span>
</div>

Connection status

<div x-data="{ online: true }" x-visible="online = $visible">
  <span x-show="online">Online</span>
  <span x-show="!online">Away</span>
</div>

License

MIT