Edit this page

up.radio [up-poll]
HTML selector

Elements with an [up-poll] attribute are reloaded from the server periodically.

Example

Assume an application layout with an unread message counter. You can use [up-poll] to refresh the counter every 30 seconds:

<div class="unread-count" up-poll>
  2 new messages
</div>

Controlling the reload interval

You may set an optional [up-interval] attribute to set the reload interval in milliseconds:

<div class="unread-count" up-poll up-interval="10000">
  2 new messages
</div>

If the value is omitted, a global default is used. You may configure the default like this:

up.radio.config.pollInterval = 10000

Controlling the source URL

The element will be reloaded from the URL from which it was originally loaded.

To reload from another URL, set an [up-source] attribute on the polling element:

<div class="unread-count" up-poll up-source="/unread-count">
  2 new messages
</div>

Skipping updates on the client

Client-side code may skip an update by preventing an up:fragment:poll event on the polling fragment.

Unpoly will also choose to skip updates under certain conditions, e.g. when the browser tab is in the background. See up.radio.config.pollEnabled for details.

When an update is skipped, Unpoly will try to poll again after the configured interval.

Skipping updates on the server

When polling a fragment periodically we want to avoid rendering unchanged content. This saves CPU time and reduces the bandwidth cost for a request/response exchange to ~1 KB.

To achieve this we timestamp your fragments with an [up-time] attribute to indicate when the underlying data was last changed. See [up-time] for a detailed example.

If the server has no more recent changes, it may skip the update by responding with an HTTP status 304 Not Modified.

When an update is skipped, Unpoly will try to poll again after the configured interval.

Stopping polling

Modifying attributes

[up-interval] optional

The reload interval in milliseconds.

Defaults to up.radio.config.pollInterval.

[up-source] optional

The URL from which to reload the fragment.

Defaults to the closest [up-source] attribute of an ancestor element.

This website uses cookies to improve usability and analyze traffic.
I accept or learn more