You're browsing the documentation for an old version of Livewire. Consider upgrading your project to Livewire 3.x.
Polling
Livewire offers a directive called wire:poll
that, when added to an element, will refresh the component every 2s
.
Polling for changes over Ajax is a lightweight, simpler alternative to something like Laravel Echo, Pusher, or any WebSocket strategy.
1<div wire:poll>2 Current time: {{ now() }}3</div>
You can customize the frequency by passing a directive modifier like 750ms
. For example:
1<div wire:poll.750ms>2 Current time: {{ now() }}3</div>
You can also specify a specific action to fire on the polling interval by passing a value to wire:poll
:
1<div wire:poll="foo">2 Current time: {{ now() }}3</div>
Now, the foo
method on the component will be called every 2 seconds.
Livewire reduces polling when the browser tab is in the background so that it doesn't bog down the server with ajax requests unnecessarily.
Only about 5% of the expected polling requests are kept.
← Previous Topic
Loading States
Next Topic →
Prefetching