Performance: Including sub-views (@include)
This affects the server-side rendering time and the size of the HTML sent to the browser, impacting the initial page load speed.
@includeWhen($showHeader, 'header') @includeWhen($showSidebar, 'sidebar') @include('content') @include('footer')
@include('header') @include('sidebar') @include('content') @include('footer') @include('comments') @include('related-posts')
| Pattern | Server Render Time | HTML Size | LCP Impact | Verdict |
|---|---|---|---|---|
| Many unconditional @include calls | High (multiple file reads) | Large (more HTML) | Slower LCP | [X] Bad |
| Conditional @include calls | Medium (fewer files) | Smaller (less HTML) | Faster LCP | [OK] Good |
@include directive do in a Laravel Blade template?@include directive is used in Blade templates to insert one view inside another, allowing code reuse.header?@include('viewname').@include('header') uses the correct parentheses and quotes. Others use invalid symbols.@include('nav')nav.blade.php contains:<nav>Menu</nav>
@include('nav') inserts the entire content of nav.blade.php into the main view.<nav>Menu</nav>, so this exact HTML will appear in the output.@include('footer')footer.blade.php does not exist in the views folder.@include('footer') tries to load footer.blade.php. If it does not exist, Laravel throws an error.title with value 'Welcome' to a sub-view header using @include?@include('view', ['key' => value]).@include('header', ['title' => 'Welcome']) uses the correct array syntax. Options A, C, and D use invalid or unsupported syntax.Pass the test and this pattern moves unknown