Elements with an [up-poll]
attribute are reloaded from the server periodically.
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>
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
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>
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.
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.
[up-poll]
attribute.up.radio.stopPolling()
with the polling element.The reload interval in milliseconds.
Defaults to up.radio.config.pollInterval
.
The URL from which to reload the fragment.
Defaults to the closest [up-source]
attribute of an ancestor element.