Polling¶
Refresh page data on an interval for live updates.
See also
Official Inertia.js docs: Polling
What Is Polling?¶
Polling lets the client automatically refresh data on a timer. This is useful for dashboards, notifications, and live metrics without WebSockets.
Frontend Usage¶
import { usePoll } from "@inertiajs/react";
export default function Dashboard() {
usePoll(
5000,
{ only: ["stats"] },
{ keepAlive: true }
);
return <StatsPanel />;
}
<script setup lang="ts">
import { usePoll } from "@inertiajs/vue3";
usePoll(5000, { only: ["stats"] }, { keepAlive: true });
</script>
<template>
<StatsPanel />
</template>
Manual Start/Stop¶
Disable auto-start and control polling manually:
import { usePoll } from "@inertiajs/react";
const poll = usePoll(2000, {}, { autoStart: false });
poll.start();
poll.stop();
<script setup lang="ts">
import { usePoll } from "@inertiajs/vue3";
const poll = usePoll(2000, {}, { autoStart: false });
poll.start();
poll.stop();
</script>
Auto-Throttling¶
Polling is throttled when the page is in the background to reduce resource
usage. Set keepAlive to true to disable background throttling.
Backend Considerations¶
No server changes are required. Consider using partial reloads (only or
except) to keep polling responses small.
See Also¶
Partial Reloads - Limit polling payloads
Prefetching - Preload data before visits
Remembering State - Preserve UI state across visits