PHPackages                             smv7/smarty-asset-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. smv7/smarty-asset-bundle

ActiveLibrary[Caching](/categories/caching)

smv7/smarty-asset-bundle
========================

Asset bundle combiner and minifier for Smarty 5.7.0 with HTTP/3 preload support and APCu learning system

v0.0.1(3mo ago)014MITPHPPHP ^8.5

Since Jan 24Pushed 2mo agoCompare

[ Source](https://github.com/smv7/smarty-asset-bundle)[ Packagist](https://packagist.org/packages/smv7/smarty-asset-bundle)[ Docs](https://github.com/smv7/smarty-asset-bundle)[ RSS](/packages/smv7-smarty-asset-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Smarty 5 Asset Bundle
=====================

[](#smarty-5-asset-bundle)

Combine, minify and preload CSS/JS assets in Smarty 5 with zero‑blocking and automatic HTTP/3 `Link` headers.

Features
--------

[](#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 `Link` headers for learned resources (requires APCu)
- **CDN ready** – configurable cache URL for any delivery network
- **Windows / Linux compatible** – path handling works everywhere

Install
-------

[](#install)

```
composer require smv7/smarty-asset-bundle
```

Quick Start
-----------

[](#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
------------------

[](#usage-in-templates)

### Basic bundle

[](#basic-bundle)

```
{bundle input=['/css/file1.css', '/css/file2.css']}
{bundle input=['/js/app.js']}
```

### With preload

[](#with-preload)

```
{bundle input=['/css/critical.css'] preload=1}
{bundle input=['/js/main.js'] defer=1 preload=1}
```

### Inline content

[](#inline-content)

```
{bundle content='.hide { display: none; }' type='css'}
{bundle content='console.log("ready");' type='js' defer=1}
```

### Media queries &amp; async loading

[](#media-queries--async-loading)

```
{bundle input=['/css/print.css'] media="print" onload="this.media='all'"}
{bundle input=['/js/analytics.js'] async=1}
```

Configuration
-------------

[](#configuration)

### AssetBundle constructor options

[](#assetbundle-constructor-options)

OptionRequiredDescription`cache_dir`yesAbsolute path to writable cache folder`cache_url`yesBase URL for cached bundles (no trailing slash)`document_root`yesServer document root (for file resolution)`enable_apcu`noEnable APCu preload learning (default: auto-detected)### `{bundle}` parameters

[](#bundle-parameters)

ParameterTypeDescription`input`array|stringFile(s) to bundle`content`stringInline CSS/JS content (instead of files)`type`stringForce type `css` or `js` (auto‑detected)`preload`boolEmit `Link` preload header for this resource`defer`boolAdd `defer` attribute (JS only)`async`boolAdd `async` attribute (JS only)`media`stringCSS media query`onload`stringJavaScript to run when CSS loadsAdvanced
--------

[](#advanced)

### Send preload headers early

[](#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

[](#disable-apcu-learning)

```
$combiner = new AssetBundle([
    // ...
    'enable_apcu' => false,
]);
```

### Clear cache

[](#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
------------

[](#requirements)

- PHP 8.5+
- Smarty 5.7+
- APCu (optional, for preload learning)
- `wikimedia/minify` (installed automatically)

Troubleshooting
---------------

[](#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
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance81

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

115d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8db5e3a318bae6155a093f17712e884a8358156ca5c8f908fbda9fa13033782?d=identicon)[smv7](/maintainers/smv7)

---

Top Contributors

[![PrometheusTitanium](https://avatars.githubusercontent.com/u/113667932?v=4)](https://github.com/PrometheusTitanium "PrometheusTitanium (1 commits)")[![smv7](https://avatars.githubusercontent.com/u/58029698?v=4)](https://github.com/smv7 "smv7 (1 commits)")

---

Tags

bundleperformancepreloadhttp2minifycacheapcuoptimizationassetssmartyspeedcombinerhttp3

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/smv7-smarty-asset-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/smv7-smarty-asset-bundle/health.svg)](https://phpackages.com/packages/smv7-smarty-asset-bundle)
```

###  Alternatives

[putyourlightson/craft-blitz

Intelligent static page caching for creating lightning-fast sites.

153471.5k29](/packages/putyourlightson-craft-blitz)[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2984.6k1](/packages/alekseykorzun-memcached-wrapper-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
