Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

motinska94's avatar

Livewire responds too slow

I built a restaurant management app for a client using livewire. And today they made a complaint saying that the app responds too slowly. What it does is basically;

  1. Click a button to select a category.
  2. Livewire makes a query and gets all products of that category and shows their names on the screen (4-10 products for each (5) category)

The whole code looks like this :

public function selectCategory($categoryId)
    {
        if ($categoryId == $this->selectedCategory){
            $this->selectedProduct = '';
            $this->selectedCategory = '';
            $this->products = [];
        }else{
            $this->selectedProduct = '';
            $this->selectedCategory = $categoryId;
            $this->products = Category::find($categoryId)->products;
            $this->fields = Category::find($categoryId)->fields; // currently it only has 1 record that belongs to 1 category
        }
 }

As you can see there's not much going on, but when I inspect the requests on the network tab, I see each of them taking somewhere between 1.5 to 3 seconds to load on button clicks. I'm guessing the problem is their hosting company and not the code, but I'm open to suggestions.

0 likes
1 reply
Snapey's avatar

Don't set these as public properties else they have to sent to and from the client on every request.

Use your browser dev tools and examine the network payload size on each request.

Remove the public products and fields then add your queries to the render method and pass them to the view as you do any controller.

Please or to participate in this conversation.