Rate limiting
Flux supports rate limiting for clicking buttons and links too frequently. The same attribute also sets the polling interval for live elements. This is useful when we want to prevent accidental double clicks, stop a frequently pressed control from sending requests too quickly, or slow a polling region down.
Rate limit a submit button
<button name="do" value="save" data-flux="submit" data-flux-rate="1">
Save
</button>
Here we allow one request per second from that button.
Rate limit a link
<a href="/dashboard" data-flux="link" data-flux-rate="2">Dashboard</a>
This allows one navigation every two seconds from that link element.
Slow down a live element
<time data-flux="live" data-flux-rate="5">12:00:00</time>
Here the same attribute means the live region polls every five seconds.
How it works
Flux stores the last trigger time per element and ignores interactions that arrive inside the defined time window. The key is based on the element’s DOM path, so the limit follows the control itself rather than the URL.
What rate limiting does not do
- it does not replace server-side validation or idempotency checks
- it does not queue requests for later
- it does not apply to plain forms or links unless a Flux button or Flux link is involved
In the final topic, we will learn how Flux can cooperate with our own JavaScript and how to inspect what it is doing. Continue to JavaScript hooks and debugging.