wire:poll
The wire:poll directive provides an easy way to automatically refresh content at regular intervals, keeping your application's data current without requiring user interaction or complex real-time technologies.
Basic Usage
This simple component demonstrates wire:poll with default intervals, custom timing, background polling, and viewport polling:
// wires/PollDemo.bx
class extends="cbwire.models.Component" {
data = {
"counter": 0,
"timestamp": ""
};
function updateCounter() {
data.counter++;
data.timestamp = dateTimeFormat(now(), "HH:mm:ss");
}
function updateStatus() {
data.timestamp = dateTimeFormat(now(), "HH:mm:ss");
}
}// wires/PollDemo.cfc
component extends="cbwire.models.Component" {
data = {
"counter" = 0,
"timestamp" = ""
};
function updateCounter() {
data.counter++;
data.timestamp = dateTimeFormat(now(), "HH:mm:ss");
}
function updateStatus() {
data.timestamp = dateTimeFormat(now(), "HH:mm:ss");
}
}What wire:poll Does
When you add wire:poll to an element, CBWIRE automatically:
Calls your method repeatedly: Executes the specified component method at regular intervals
Updates content automatically: Refreshes the display with new data from each polling request
Optimizes performance: Intelligently throttles polling when the browser tab is inactive
Manages resources: Uses a default 2.5-second interval that balances freshness with server load
Available Modifiers
You can customize polling behavior with these modifiers:
Timing:
.5s,.15s,.5000ms- Set custom polling intervalsBackground:
.keep-alive- Continue polling when browser tab is inactiveViewport:
.visible- Poll only when element is visible on screen
Combine modifiers as needed: wire:poll.10s.keep-alive or wire:poll.15s.visible
Was this helpful?