Reducing Server Load in Livewire with Computed Properties
Stop sending redundant data to the client. Learn how to use Livewire Computed Properties to cache server-side calculations and optimize your Laravel application's performance.
31 Mar 2026, 19:55 UTC

The Problem: Redundant Queries in Blade Views
When building interactive interfaces with Livewire, it is common to need a piece of data derived from your state—such as a total count of filtered records or a user's permission level. The intuitive approach is to assign this value to a public property during the mount() method or an update hook.
However, this creates two technical inefficiencies. First, public properties are serialized and sent to the browser in every request payload, increasing bandwidth usage for data the client doesn't actually need to modify. Second, if you calculate a value manually in a method and call that method multiple times in your Blade template, you risk executing the same expensive database query repeatedly during a single render cycle.
The takeaway: Use Computed Properties to derive data that is cached for the duration of a single request, keeping your network payloads slim and your database queries minimal.
How Computed Properties Work
A computed property is a method that Livewire treats as a property. Unlike standard public properties, computed properties are not stored in the component's state on the frontend. Instead, they are resolved on the server only when accessed in the view or within the component class.
In Livewire v3, this is achieved using the #[Computed] attribute. When you access a computed property, Livewire caches the result. If you reference $this->userCount five times in your HTML, the underlying logic executes exactly once.
Implementation Example: Filtered Order Dashboard
Consider a dashboard where you display a total order count in both the page header and a summary sidebar. Using a standard method would trigger two queries; using a public property would send the count back and forth to the browser unnecessarily.
namespace App\Livewire;\n\nuse Livewire\Component;\nuse App\Models\Order;\nuse Livewire\Attributes\;\n\nclass OrderDashboard extends Component\n{
public $status = 'pending';\n\n #[Computed]\n public function orders()\n {
// This query runs once per request, regardless of how many times it is called in Blade\n return Order::where('status', $this->status)->get();\n }\n\n public function render()\n {
return view('livewire.order-dashboard');\n }\n}
In your Blade template, you access the computed property as if it were a variable, omitting the parentheses:
<div>
<h1>Pending Orders: {{ $this->orders->count() }}</h1>
<div class="sidebar">
<p>Total items to process: {{ $this->orders->count() }}</p>
</div>
</div>
Verification and Diagnostics
To verify that the caching is working, you can use Laravel's query log. Run the following in a local environment:
- Enable the query log:
DB::enableQueryLog(); - Refresh the Livewire component page.
- Dump the log:
dd(DB::getQueryLog());
If implemented correctly, you will see only one SELECT count(*) query, even though the count is displayed in two different locations in the UI.
Trade-offs and Limitations
While powerful, computed properties are not a universal replacement for state. Keep these constraints in mind:
- Request Lifespan: The cache only exists for the current request. On the next server round-trip (e.g., after a user clicks a button), the property is recalculated.
- Naming Collisions: You cannot have a public property and a computed property with the same name. If you have
public $ordersand a#[Computed] public function orders(), the application will throw an error. - Latency: Because the logic runs on the server during the render phase, extremely complex calculations or slow API calls inside a computed property will delay the response time for the entire component.
Decision Matrix: Public vs. Computed
| Feature | Public Property | Computed Property |
|---|---|---|
| Sent to Browser | Yes (Serialized) | No |
| Cached per Request | N/A (Stored) | Yes |
| Client-side Editable | Yes (via wire:model) | No (Read-only) |
| Best Use Case | Form inputs, UI toggles | DB queries, derived totals |
Actionable Summary
Audit your current Livewire components for public properties that are only used for display and are derived from other state. Move these to #[Computed] methods to reduce the size of your network payloads and eliminate redundant database queries. This simple shift improves both the scalability of your server and the perceived performance for the end user.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.