Polling

Polling provides a way to repeatedly update the UI using server data. Two polling approaches supported by htmx are fixed-rate polling and load polling.

Fixed-Rate Polling

Fixed-rate polling sends requests at regular intervals.

The following HTML reports the current score of an NFL game. It sends a GET request to the /score endpoint every five seconds. Note the use of hx-trigger value every 5s. The endpoint returns updated score text that replaces the contents of the body element.

images/htmx-fixed-rate-polling.png
 <html>
  <head>
  <title>Fixed Rate Polling with htmx</title>
  <link rel=​"stylesheet"​ href=​"styles.css"​ />
  <script src=​ ...

Get Server-Driven Web Apps with htmx now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.