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

wassy83's avatar

Very slow response if there is an error in laravel view or component with inline javascript

I'm new to laravel and I'm building a pure laravel 9 app(no vue, nodejs or other frameworks just laravel + vanilla js). If I have any kind of error (even a typo like ech 'a letter is missing'; ) in a laravel child view or component, the error page response tooks more then 20seconds to appears. After investigating this for an entire day, I found that the time of response is proportionate to the length of the inline javascript code present in the blade.php file. In example if I have an inline console log with a lot of text(just for simulation) the more the text is long the more time the page error will takes to respond. If I place the js in an external script or in the layout.blade.php root file, the error page will load superfast. I know that inline script is a bad practice, especially in this case that we are talking about 500 rows of pure JS, but in some conditions this is my way to work and take things ordered, so I want to fix this.

UPDATE:

I forgot to specify that if no errors are present, the page will load superfast under 100ms

HERE THERE IS A SCREEN OF MY INSPECTOR

THIS IS THE RELATED CONTROLLER

class DisponibilitaController extends Controller
{

    // Show dashboard disponibilità
    public function index(request $request){

        $fields = [
            'status' => 'STATO',
            'reference' => 'REFERENCE',
            'option_date' => 'OPTION DATE',
            'departure_port' => 'DA',
            'arrival_port' => 'A',
            'departure_date' => 'DATA PARTENZA',
            'arrival_date' => 'DATA ARRIVO',
            'season' => 'STAGIONALITÀ',
            'notes' => 'APPUNTI',
            'accomodations' => 'SISTEMAZIONI',
            'vehicles' => 'VEICOLI',
            'name' => 'NOME',
            'surname' => 'COGNOME'
        ];
        
        return view('disponibilita.dashboard',

            [
            "title" => "Gestione disponibilita",
            "id" => "disponibilitaTable",
            "thead" => array_values($fields),
            "data" => Disponibilita::latest()->paginate(3, array_keys($fields)),
            "theadhelpers" => '
                <input type="checkbox" id="select-all">
                <i class="fa-solid fa-reply-all"></i>',
            "tbodyhelpers" => '
                    <input type="checkbox" class="select-row">
                    <i class="fa-solid fa-lock lock"></i>
                    <i class="fa-solid fa-pencil edit"></i>
                    <i class="fa-solid fa-circle-minus delete"></i>
                    <i class="fa-solid fa-maximize maximize"></i>'
            ]
            
        );

    }
........

THIS IS THE MAIN LAYOUT BLADE

<!DOCTYPE html>
<html lang="en">
@include("partials._head")
<body>
    <div class="page">
        @include("partials._sidebar")
        <div class="content">
            <header>
                <h1>{{ucfirst($title)}}</h1>
            </header>
            @yield('content')
        </div>
    </div>
    @include("partials._footer")
    @stack('scripts')
</body>
</html>

AND THIS IS THE CHILD VIEW THAT I'M CALLING IN THE CONTROLLER WITH A TYPO ERROR AT THE BEGINNING

@php
ech 'missing a letter';
@endphp
@extends('layouts.layout')
@section('content')

@if (session('message'))
    <x-alert>{{ session('message') }}</x-alert>
@endif

<div class="dispo-list listings fadeInBottom">
    <div class="helper-bar">
        <div class="bulk-buttons">
            <x-button href="#" icon="plus" class="create">Aggiungi Disponibilità</x-button>
            <x-button href="#" icon="plus" class="">OPTION DATE</x-button>
            <x-button href="#" icon="plus" class="">BLOCCA</x-button>
            <x-button href="#" icon="plus" class="">CANCELLA</x-button>
            <x-button href="#" icon="plus" class="">EMETTI</x-button>
        </div>
        <div class="filter-dispo-ctn">
            <form id="filters-form" autocomplete="off">
                @csrf
                <div class="filters-ctn">
                    <div class="filter-ctn text-search">
                        <input id="text-search" type="text" name="text-search" value="" placeholder="Cerca per testo">
                    </div>
                    <div class="filter-group date-search">
                        <div class="filter-ctn date-from-search">
                            <input id="date-from-search" type="text" name="date-from-search" value="" placeholder="Partenze dal">
                        </div>
                        <div class="filter-ctn date-to-search">
                            <input id="date-to-search" type="text" name="date-to-search" value="" placeholder="Fino al">
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <x-table :id="$id" :thead="$thead" :theadhelpers="$theadhelpers" :tbodyhelpers="$tbodyhelpers" :data="$data" tfoot />
</div>
@endsection

@pushOnce('scripts')
<script>

/**
 *  Here the more inline javascript I place, the more laravel error page will take to
 *  respond, this is not related to what kind of functions I'm running but to 
 *  how much plain text I'm writing, so even a console.log with 300 words
 *  will add 30 seconds of delay to respond 
*/

console.log("here I place a very long text around 300words to got 30 seconds delay................")

</script>
@endPushOnce
0 likes
16 replies
sr57's avatar

Did you put a console.log with the row number(and a timestamp) in your inline scripts?

wassy83's avatar

@sr57 Dear I updated the question adding the way I'm calling the blades. At the end you will find the console.log part, but as I'm clarifing in the comment above console.log, the response time is just related on how much plain text I'm adding inline into the scipt tags. It looks like is somehow parsing the javascript text before showing me the error page. If I place the inline scripts directly into the layout blade it will show error page superfast.

sr57's avatar

@wassy83

Understood, I just suggest you ways to understand the real code your are running.

2nd way) did you have a look to your html source page?

wassy83's avatar

@sr57 sorry what do you mean "did you have a look to your html source page" I wrote my layout.blade code in the fist post, this is how the html page is made, I can tell you that if I place the inline script directly in layout.blade, the error page will run superfast, so the problem is only related on child views/components

sr57's avatar

@wassy83

See blade as a macro above php, it generates standard php page that runs on your server.

You should have a look on the generated pages (low & fast ones) and understand the root cause. There is no magic, it's only js code that you are running too often.

wassy83's avatar

@sr57 ok I will try to go deeper, but honestly I checked everything. I will update you if I found something. thank you

wassy83's avatar

@sr57 just to give you a little update, I noticed that the delay time is not related on how much js I put inside the tags, but on the entire plain text of the view/component, I tried to remove everthing from the child view with the typo error, and just leave a p tag with 500 words inside(like lorem ipsum dolor). The more words I put inside the tags, the more the error page will take to be showed(around 10second every 1000words). I don't know.

wassy83's avatar

@click Dear I already checked this post, but I didn't installed anything with laravel, is a basic clean setup, but how can I check if this error handler is installed(not by me for sure)?

click's avatar

@wassy83 If you didn't configure anything custom than it should not be an issue. As the default is to log the error to a file.

Try disabling one of the flare features as described here: https://flareapp.io/docs/ignition-for-laravel/controlling-collected-data. If the speed improves when turning of collect_git_information for example you know it is related to your git client. Or report_view_data => false might help you.

See https://flareapp.io/docs/ignition-for-laravel/installation on how to publish the config files.

wassy83's avatar

@click nothing changes disabling those features, first of all I would like to understand if is something related to my setup or if is a normal behaviour that long text child views will throw slow error pages

click's avatar

@wassy83 It is something related to your setup. It is a bit hard to keep guessing if above does not help you speed it up but you can try for example:

  • Try setting debug=false in your .env. This will show you just the 500 error page and not the fancy error page.
  • Try throwing an error in public/index.php on one of the first lines to see what happens
  • Try playing around with your log settings config/logging.php
wassy83's avatar

@click

Try setting debug=false in your .env. This will show you just the 500 error page and not the fancy error page

nothing changes except that is not showing error informations

Try throwing an error in public/index.php on one of the first lines to see what happens

As I already wrote, if I place the inline script directly in layout.blade, the error page will run superfast so same thing in index.php

Try playing around with your log settings config/logging.php

I'm trying without success, honestly I think that something related on how I call the view in my controller, like a huge loop if the error is inside a component. I don't think is related on logging engine.

sr57's avatar

@wassy83

Any update?

Did you compare the wo source pages (low and fast)?

Remove all unnecessary stuffs and share both of them.

wassy83's avatar

CPU goes 100% for the entire time I'm waiting for the error response

wassy83's avatar

OK I think this update is important, if I run my laravel app through my apache web server(so not using php artisan) the error page will load superfast, so this cannot be related to some code error. Usually I run my laravel app in this way

php artisan serve --host 192.168.25.209

where 192.168.25.209 is a server in my network that is hosting my laravel app

Please or to participate in this conversation.