-
Notifications
You must be signed in to change notification settings - Fork 0
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.
<button name="do" value="save" data-flux="submit" data-flux-rate="1">
Save
</button>Here we allow one request per second from that button.
<a href="/dashboard" data-flux="link" data-flux-rate="2">Dashboard</a>This allows one navigation every two seconds from that link 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.
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.
- 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.
PHP.GT/Flux is a separately maintained component of PHP.GT/WebEngine.