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

aureliee123's avatar

laravel website slow loading time

Hello , i have an e-commerce website built with laravel and bootstrap i am suffering from a very very very slow loading time but i can't figure out where is the problem here's the link : http://petit.orcloud.dz/ any help will be very much appreciated

THANK YOU

0 likes
33 replies
lat4732's avatar

The reason may be at server level, it may be at the code optimization level... The reasons are many. I advise you to start by installing debugbar in your application. It will give you detailed information about everything that the page is loading and you can optimize whatever you want.

aureliee123's avatar

@Sinnbeck thank you for your answer i reduced the number of queries on the front page but the loading time didn't really improve

Sinnbeck's avatar

@aureliee123 better but still alot of similar queries. I'm sure you can inprove it even more. 40 queries

pom's avatar

Your server response time is terrible the Time to First Byte (TTFB) is around 4 seconds. Your initial payload is 4.9MB How/where is it hosted?

Your images are another bottleneck - around 5 seconds (probably server related)

https://petit.orcloud.dz/storage/comments/sXj8Axg0xbI3M9rH1y5zGhlWqQr5GHs8VFl2GBui.jpg is > 400KB you need to optimise and resize your images.

You also have render-blocking resources. Defer loading your non-essential assets.

Minify your assets (e.g. CSS, JS).

aureliee123's avatar

@pom thank you for your answer the ttfb is awful i'm hosting the website in amazon i have another website in the same server https://v1.tabland.shop/ and it's really fast

i minified the js and css files but still same issue

Sinnbeck's avatar

@aureliee123 last I checked you still had alot of queries on the front page. Show your controller for the index method

pom's avatar

@aureliee123 I hate to be the bearer of bad news but that site is just as slow. While the time to first interaction is around 2 seconds (acceptable) you have 23 seconds worth of images being downloaded.

https://v1.tabland.shop/storage/produits/gJvGKBqkY0AeEhAxt3m5DvwtrbqMrRhrJ1cJHgTh.jpeg is almost 10MB with a resolution of 3780x5314 😲 total payload is 33.5MB

Are you preloading your images with some sort of JS on the new site?

OMG I just clicked on /produits - 58.8MB I can guarantee you're losing customers.

aureliee123's avatar

i'm showing 6 categories on the front page and 5 products for each category so that's a total of 30 products ( 30 images ) can this possibly be the reason of the slow ttfb ?

aureliee123's avatar

@Sinnbeck

public function index() {

    $produits = Produit::where('afficher', 1)->with('promotion','categorie')
    ->orderBy('prio')->get();

    $comments = Comment::where('etat',1)->with('client')->get();

    $categories = Categorie::where('afficher',1)->with('img')
    ->get()->each(function ($feed) {
        $feed->load('produits.categorie')->take(5);
    });
    
    return view('index', compact('produits', 'categories','comments'));
}
Sinnbeck's avatar

@aureliee123 this seems to make a bunch of queries

$categories = Categorie::where('afficher',1)->with('img')
    ->get()->each(function ($feed) {
        $feed->load('produits.categorie')->take(5);
    });
    

Use with directly instead

Sinnbeck's avatar

@aureliee123 something like this if I understood you correctly

$categories = Categorie::where('afficher',1)->with('img')->with(['produits' => function ($q) {
    $q->with('categorie')->limit(5);
})->get();
1 like
aureliee123's avatar

@sinnbeck $categories = Categorie::where('afficher',1)->with('img')->with(['produits' => function ($q) { $q->with('categorie')->limit(5); }])->get();

this code didn't work it's not returning 5 products for each category

Sinnbeck's avatar

@aureliee123 weird. I could have sworn it would. I am not a computer currently so I am not able to test it out

Snapey's avatar

do you have a route that returns a simple view ( or create one ). One with no database queries. You can call this and measure ttfb. it should be less than 200ms

Snapey's avatar

Its not a 'server' issue as all the other menu items respond between 40 and 90ms (debugbar timeline)

definitely something you are doing in the home page route

aureliee123's avatar

@Snapey something i'm doing in the home page route as in too many queries ? or too much rendering ?

Snapey's avatar

@aureliee123 something you are doing. other pages have more database requests and serve the page quicker

do you have any view composers?

any of the view components have code in them and in particular, loops?

are you using cloud storage for the images?

aureliee123's avatar

@Snapey i'm not using any view composers but i do have loops

@foreach ($categories as $key=>$value) <div class="tab-pane fade {{$key==0?"active show":""}} position-relative" id="pills-{{$value->id}}" role="tabpanel" aria-labelledby="pills-monstre-{{$value->id}}">

                <div class="swiper-container mySwiper2 h-max">
                    <div class="swiper-wrapper clr-alternate h-max">
                        @foreach ($value->produits->take(5) as $item)
                            <div  data-backdrop="false" style="z-index:7000000 !important" class="modal fade" id="exampleModalCenter{{$item->id}}Promo"   tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                                <div class="modal-dialog" 

do you think the problem is coming from the loops ? i'm using loops on the good website ( https://v1.tabland.shop/ ) too and it's not causing issues

rodrigo.pedra's avatar

@aureliee123 I visited your site and see you installed debug bar as suggested.

Which is great. But please don't enable it on your production server. Read the README at debugbar repository to learn how to disable it on production.

From the info in the debugbar it doesn't see you are doing nothing fancy. Network tab also seems ok: bundled and minimized JS, not many requests to the server (not a problem as server uses HTTP/2), and just two third party requests from a CDN.

So you might have a very small server, or if you are running database and web server on the same "machine", you could consider giving it more RAM. Ideally database and webserver should run in different machines, but I understand it is not possible for every project.

As debugbar is enabled in production, I assume you are not optimizing your composer file in production, neither caching config or routes. These are small wins which can shave off about 10-15% on server processing time for each request.

Please read very carefully this section on Laravel's official documentation, to learn more about these suggestions:

https://laravel.com/docs/9.x/deployment

Other than those suggestions I don't see how else you could improve it with the information provided.

Good luck

1 like
Snapey's avatar

@aureliee123 no it should be fine, but you don't explain what you are doing in the home route

aureliee123's avatar

@Snapey this is the index page function

public function index() {

    $products = Product::where('show', 1)->with('promotion','category')
    ->orderBy('prio')->get();


    $comments = Comment::where('state',1)->with('client')->get();

    $categories = 
    Category::where('show',1)->with('img','products.categorie','products.promotion')
    ->get();

  
    
    return view('index', compact('products', 'categories','comments'));
}

and in the view i am showing $products and i'm iterating over the categories and showing 5 products of each category that's about it

Please or to participate in this conversation.