In this episode, we're looking at how to reduce the number of requests Livewire makes to the backend when users type in an input. You've probably noticed that with the default settings, Livewire sends a request every time the user makes a change—like, literally every keypress! That can be a lot if someone is typing quickly.
To address this, we first revisit the concept of input debouncing and see how we can increase the default debounce time. We spin up a quick search
component with an input wired to a query
property. By default, the debounce is set at 150 milliseconds in Livewire, but you can easily bump this up to something like 500 milliseconds using the debounce
modifier. This means that as you type, the backend will only get updates every half a second rather than on every key.
We see a quick demo of how this simple change can drastically cut down the number of requests—typing "code course" in one go only fires off a single request at 500ms, but would have sent several at the default. If your UI doesn't need instant updates per letter—and especially if you're working with things like searching or data tables—upping the debounce amount can really boost performance and reduce server load, without sacrificing user experience.