degecko/laravel-blade-inline
Composer 安装命令:
composer require degecko/laravel-blade-inline
包简介
Inline Blade partials at compile time for faster rendering in loops
README 文档
README
Inline Blade partials at compile time for faster rendering in loops.
The problem
When you use @include inside a loop, Laravel's view factory resolves the file, creates a new view instance, and compiles the template on every iteration. For a page rendering 100+ cards, this overhead adds up.
{{-- Each iteration pays the full view factory cost --}} @foreach ($items as $item) @include('components.card') @endforeach
The solution
@inline compiles the partial once and embeds the resulting PHP directly into the parent view at compile time. At runtime, the loop body is just plain PHP — no view factory, no file lookups, no ComponentAttributeBag.
{{-- Compiled once, inlined as raw PHP --}} @foreach ($items as $item) @inline('components.card') @endforeach
Benchmarks
Rendering an escort listing card across different loop sizes (Laravel 13, PHP 8.4):
| Cards | @include |
@inline |
Improvement |
|---|---|---|---|
| 13 | 1.61ms | 1.51ms | 6% |
| 104 | 13.6ms | 10.1ms | 26% |
| 260 | 32.6ms | 27.6ms | 16% |
The improvement grows with template complexity and loop size.
Installation
composer require degecko/laravel-blade-inline
The service provider is auto-discovered.
Usage
Basic usage
@inline works like @include but the partial shares the parent's variable scope:
@foreach ($products as $product) @inline('components.product-card') @endforeach
The $product variable is available inside the partial automatically — no need to pass it explicitly.
Passing variables
You can set local variables for the partial:
@foreach ($products as $product) @inline('components.product-card', [ 'highlight' => $loop->first, 'lazy' => $loop->index > 6, ]) @endforeach
How it works
- At compile time,
@inlinereads the partial's Blade source - Strips any
@propsdirective (unnecessary since variables come from the parent scope) - Compiles the Blade to PHP via
Blade::compileString() - Embeds the compiled PHP directly into the parent view
The result: the partial's logic becomes part of the parent view's compiled PHP file. At runtime, there's zero overhead from view resolution.
Important notes
- Shared scope: The partial accesses the same variables as the parent view. No isolated scope like
@include. - No
$attributes: Since@propsis stripped, the$attributesbag is not available. Use explicit variables instead. - Cache: Changes to the partial require
php artisan view:clearto take effect (same as any Blade change in production). - All Blade directives work:
@if,@foreach,@php/@endphp,{{ }}, etc. are all fully supported.
When to use
Use @inline when:
- A partial is rendered many times in a loop (listing pages, tables, feeds)
- The partial doesn't need isolated variable scope
- You want to eliminate view factory overhead
Stick with @include when:
- The partial is rendered once or twice (no loop overhead to save)
- You need isolated variable scope
- You use
$attributesor component features
License
MIT
degecko/laravel-blade-inline 适用场景与选型建议
degecko/laravel-blade-inline 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 7, 最近一次更新时间为 2026 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「inline」 「laravel」 「blade」 「partial」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 degecko/laravel-blade-inline 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 degecko/laravel-blade-inline 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 degecko/laravel-blade-inline 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
A Symfony bundle for using the CssToInlineStyles translator by tijsverkoyen
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
A Twig extension to insert css as inline styles with a tag
A Laravel Nova field for displaying morphTo relationship inline.
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-13