You're browsing the documentation for an old version of Livewire. Consider upgrading your project to Livewire 3.x.

Prefetching

Be amazing at Livewire
with our in-depth screencasts.
Watch Now

Introduction

Livewire offers the ability to "prefetch" the result of an action on mouseover. Toggling display content is a common use case.

This is useful for cases when an action DOES NOT (like writing to session or database) perform side effects. If the action you are "pre-fetching" has side-effects, the side-effects will be unpredictably executed.

Add the prefetch modifier to an action to enable this behavior:

        
1<button wire:click.prefetch="toggleContent">Show Content</button>
2 
3@if ($contentIsVisible)
4 <span>Some Content...</span>
5@endif

Now, when the mouse enters the "Show Content" button, Livewire will fetch the result of the "toggleContent" action in the background. If the button is actually clicked, it will display the content on the page without sending another network request. If the button is NOT clicked, the prefetched response will be thrown away.

← Previous Topic Polling
Next Topic → Offline State