我正在使用 laravel 刀片文件,我想知道这种方法是否会降低我的网站速度。这是我的文件结构:
show.blade.php 文件:
<div class="table-sections">
...
@include('elements/table',['name' => 'table1','blocks' => $blocks1])
...
@include('elements/table',['name' => 'table2','blocks' => $blocks2])
...
</div>
Run Code Online (Sandbox Code Playgroud)
table.blade.php 文件:
...
@foreach($blocks as $block)
...
@foreach($block['sections'] as $section)
...
@foreach($section['rows'] as $row)
...
@include('elements/row','row' => $row)
...
@endforeach
...
@endforeach
...
@endforeach
...
Run Code Online (Sandbox Code Playgroud)
row.blade.php 文件:
...
@foreach($row['attributes'] as $attribute)
...
// Making the '<td>' elements with their respective attributes and html
...
@endforeach
...
Run Code Online (Sandbox Code Playgroud)
我有很多嵌套的“foreach”块控制部分,所以我想知道在这种情况下不使用刀片是否更好(例如对于 row.blade.php 文件)
你有什么建议?
太多的嵌套,在 Laravel 中确实是一种不好的做法。我们试图使代码干净,但这有时会导致性能权衡。这就是为什么我最终决定创建一个小型库来扁平化生产中的刀片,从而将性能提高多达 10 倍。
从这里尝试: https: //packagist.org/packages/te-cho/compile-blades
基本上,它所做的就是获取刀片文件,并将包含和生成放在一个刀片文件中,而不包含或生成。