smv7/smarty-asset-bundle
Composer 安装命令:
composer require smv7/smarty-asset-bundle
包简介
Asset bundle combiner and minifier for Smarty 5.7.0 with HTTP/3 preload support and APCu learning system
关键字:
README 文档
README
Combine, minify and preload CSS/JS assets in Smarty 5 with zero‑blocking and automatic HTTP/3 Link headers.
Features
- Zero‑blocking – first request serves original files, cache generates in background
- Smart caching – content‑based hashing for instant cache validation
- HTTP/3 preload – automatic
Linkheaders for learned resources (requires APCu) - CDN ready – configurable cache URL for any delivery network
- Windows / Linux compatible – path handling works everywhere
Install
composer require smv7/smarty-asset-bundle
Quick Start
require_once 'vendor/autoload.php'; use SmartyBundler\AssetBundle; use SmartyBundler\BundleExtension; $combiner = new AssetBundle([ 'cache_dir' => __DIR__ . '/cache/assets', // must be writable 'cache_url' => 'https://cdn.example.com/assets', 'document_root' => $_SERVER['DOCUMENT_ROOT'], // required for file resolution 'enable_apcu' => extension_loaded('apcu'), // auto‑detect ]); // Send preload headers learned from previous requests (optional) $combiner->sendCachedPreloads('main.tpl'); // Register Smarty plugin $smarty->addExtension(new BundleExtension($combiner)); $smarty->display('main.tpl');
Usage in Templates
Basic bundle
{bundle input=['/css/file1.css', '/css/file2.css']} {bundle input=['/js/app.js']}
With preload
{bundle input=['/css/critical.css'] preload=1} {bundle input=['/js/main.js'] defer=1 preload=1}
Inline content
{bundle content='.hide { display: none; }' type='css'} {bundle content='console.log("ready");' type='js' defer=1}
Media queries & async loading
{bundle input=['/css/print.css'] media="print" onload="this.media='all'"} {bundle input=['/js/analytics.js'] async=1}
Configuration
AssetBundle constructor options
| Option | Required | Description |
|---|---|---|
cache_dir |
yes | Absolute path to writable cache folder |
cache_url |
yes | Base URL for cached bundles (no trailing slash) |
document_root |
yes | Server document root (for file resolution) |
enable_apcu |
no | Enable APCu preload learning (default: auto-detected) |
{bundle} parameters
| Parameter | Type | Description |
|---|---|---|
input |
array|string | File(s) to bundle |
content |
string | Inline CSS/JS content (instead of files) |
type |
string | Force type css or js (auto‑detected) |
preload |
bool | Emit Link preload header for this resource |
defer |
bool | Add defer attribute (JS only) |
async |
bool | Add async attribute (JS only) |
media |
string | CSS media query |
onload |
string | JavaScript to run when CSS loads |
Advanced
Send preload headers early
Call sendCachedPreloads() before any output to let the browser discover critical resources sooner. You can pass a template name (used as APCu key).
Disable APCu learning
$combiner = new AssetBundle([ // ... 'enable_apcu' => false, ]);
Clear cache
Manually delete all files in cache_dir or use the cache manager’s method if you expose it:
// If you add a getter for CacheManager $combiner->getCacheManager()->clearCache();
Requirements
- PHP 8.5+
- Smarty 5.7+
- APCu (optional, for preload learning)
wikimedia/minify(installed automatically)
Troubleshooting
Empty src/href attributes on Windows
Make sure all paths use forward slashes. The latest version normalises paths automatically – update to the current release.
Cache not written
Check that cache_dir exists and is writable by the web server.
Preload headers not sent
Verify APCu is installed and enable_apcu is true. Headers are sent only once per request.
Double slashes in URLs
Do not add a trailing slash to cache_url – the library adds it internally.
APCu required warning during install
The package checks for APCu; if you don’t need preload, you can ignore the warning or set enable_apcu to false in config.
License
MIT
smv7/smarty-asset-bundle 适用场景与选型建议
smv7/smarty-asset-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「assets」 「cache」 「smarty」 「bundle」 「minify」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 smv7/smarty-asset-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 smv7/smarty-asset-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 smv7/smarty-asset-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
g4 application profiler package
repository php library
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
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>.
Caching and compression for Twig assets (JavaScript and CSS).
统计信息
- 总下载量: 28
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 43
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-16