-
Notifications
You must be signed in to change notification settings - Fork 224
/
prefetching.blade.php
23 lines (16 loc) · 1.02 KB
/
prefetching.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
* [Introduction](#introduction)
## Introduction {#introduction}
Livewire offers the ability to "prefetch" the result of an action on mouseover. Toggling display content is a common use case.
@component('components.warning')
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.
@endcomponent
Add the `prefetch` modifier to an action to enable this behavior:
@component('components.code')
@verbatim
<button wire:click.prefetch="toggleContent">Show Content</button>
@if ($contentIsVisible)
<span>Some Content...</span>
@endif
@endverbatim
@endcomponent
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.