Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel blades performance

Tags:

php

laravel

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?

like image 993
dani24 Avatar asked Jun 05 '15 18:06

dani24


1 Answers

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.

like image 168
Abd Rmdn Avatar answered Sep 21 '22 22:09

Abd Rmdn