简体   繁体   中英

Laravel blades performance

I'm using the laravel blades files and I wanted to know if this methodology can slow my site. This is my structure of files:

show.blade.php file:

<div class="table-sections">
   ...
   @include('elements/table',['name' => 'table1','blocks' => $blocks1])
   ...
   @include('elements/table',['name' => 'table2','blocks' => $blocks2])
   ...
</div>

table.blade.php file:

...
@foreach($blocks as $block)
   ...
   @foreach($block['sections'] as $section)
      ...
      @foreach($section['rows'] as $row)
          ...
          @include('elements/row','row' => $row)
          ...
      @endforeach
      ...
   @endforeach
   ...
@endforeach
...

row.blade.php file :

...
@foreach($row['attributes'] as $attribute)
   ...
   // Making the '<td>' elements with their respective attributes and html
   ...
@endforeach
...

I have a lot of nested 'foreach' block control sections, so I wanted to know if in this cases is better to not use the blades (for instance for the row.blade.php file)

What do you suggest?

Too much nesting, is really a bad practice in Laravel. we try to make our code clean, but that causes sometimes a performance tradeoff. thats why i ended up deciding to create a small library that flattens the blade on production, which improves the performance up to x10 times.

try it from here: https://packagist.org/packages/te-cho/compile-blades

basically, all it does is that it takes the blade file and it puts the includes and yields in one blade file without no includes nor yielding.

According to official Laravel documentation

all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application

I suppose if you don't tamper with your cache config, the above statement puts it straight forward.

In other words, don't be scared to take full advantage of blade templating engine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM