Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Minifier Bundle Laravel Package

sema/minifier-bundle

Sema Minifier Bundle integrates configurable HTML, CSS, and JavaScript minification into Symfony applications. It compresses responses and assets on the fly, supports caching and filters, and helps reduce page weight, load times, and bandwidth with minimal changes to existing templates.

View on GitHub
Deep Wiki
Context7

Getting Started

The bundle targets older Symfony versions (2.x/3.x era), so first confirm your kernel style matches. Register Sema\Bundle\MinifierBundle\SemaMinifierBundle in app/AppKernel.php (or config/bundles.php if you've adapted it) and then import the bundle's default config:

# app/config/config.yml
sema_minifier:
    # defaults are fine to start; see the bundle's Resources/config for full options

Install with composer require sema/minifier-bundle and clear the Symfony cache. There is no separate binary or service to run — all minification happens in PHP, so no Java VM is required.

Look first at: the bundle's Resources/config/services.yml and the two main entry points — the response listener (HTML minification) and the Twig extension / asset helper (JS+CSS combining). Those are where 90% of day-to-day interaction happens.

First use case: enable HTML minification for your production responses only. Verify by requesting a page in prod and inspecting the source — whitespace inside <script>/<pre> and inline event handlers should be preserved, everything else stripped.

Implementation Patterns

HTML output minification. This is typically wired as a kernel response listener. Keep it off in dev/test and on in prod:

# app/config/config_prod.yml
sema_minifier:
    html:
        enabled: true

Because the listener operates on the Response object, it runs after your controllers and Twig rendering — no changes needed to templates. If you need to skip minification for a specific response (e.g. a JSON or XML endpoint, or an HTML email body), set a header/flag in that controller rather than disabling the bundle globally.

Combining and minifying CSS/JS. The bundle's combining support typically works by declaring groups and pointing a template tag at them. A common shape:

{# prod: one request per group #}
{{ sema_minifier_css(['@AppBundle/Resources/public/css/base.css', '@AppBundle/Resources/public/css/app.css']) }}
{{ sema_minifier_js(['@AppBundle/Resources/public/js/vendor.js', '@AppBundle/Resources/public/js/app.js']) }}

The bundle writes the concatenated/minified file into a cache directory and returns the public URL. This is the "poor man's asset pipeline" pattern — a reasonable alternative to Assetic when you cannot add Node or a JVM to your build host.

Group by page, not by file. Rather than one giant bundle, define per-layout groups (e.g. base.css, admin.css) so that landing pages aren't paying for admin styles. The combine step is cheap; the HTTP request savings are what matter.

Cache-busting. Because the output filename is deterministic (usually a hash of the input set), the URL changes when inputs change — that's your cache-buster. If you see stale assets after deploy, the cache directory was not cleared; wire cache:clear into your deploy step.

Dev/prod parity. Feed the Twig helper unconditionally, but let the bundle's config decide whether to combine. In dev you want individual files so source maps and browser devtools stay usable; in prod you want the combined output.

Gotchas and Tips

  • Symfony version drift is the biggest risk. This bundle predates Symfony Flex and the modern bundle API. On Symfony 4+ you'll need to manually add it to config/bundles.php and translate app/config/*.yml to config/packages/*.yaml. Expect the service definitions to reference old %kernel.root_dir% style parameters that were renamed (%kernel.project_dir%).

  • <pre>, <textarea>, and inline <script> are the classic HTML minifier casualties. Always smoke-test pages with code samples and templating output before shipping. If your HTML minifier has a "safe" vs "aggressive" mode, prefer safe in prod until you trust it.

  • Write permissions on the cache directory. The combined files land under something like web/minified/ or var/cache/minified/. If the web server user cannot write there, you get silent fallbacks or 404s on the generated URLs. Check the directory after your first request in prod.

  • Minification of already-minified libraries is usually fine but occasionally breaks. Some third-party JS (older jQuery plugins, source-map-dependent code) relies on specific line endings or trailing semicolons. Test your vendor bundle specifically; if it breaks, exclude that file from the JS group and load it separately.

  • Order matters in JS groups. The combiner concatenates in input order — dependencies must come first. There's no module resolution; you're responsible for the sequence.

  • debug mode interactions. If you have a debug flag in config, make sure it's driven by %kernel.debug% so app_dev.php doesn't get combined, cached assets while you're iterating on CSS.

  • Extension points are thin. You can usually swap the underlying minifier implementation via a service alias (the bundle delegates to a PHP library rather than shelling out). If you need a specific minifier (YUI, Closure, esbuild), this bundle isn't the right tool — use a real build pipeline instead. The value proposition here is "no JVM, no Node, pure PHP."

  • Debugging a broken combined file: temporarily point the Twig helper at a single file, or disable combining for one group, and bisect. Because the output is a flat concatenation, stack traces in the browser point at line numbers in the combined file — cross-reference against the group order.

  • Unmaintained status (last meaningful activity years ago). Pin the version, vendor it into your build if necessary, and treat it as replaceable — the pattern it implements (concatenate + PHP minify) is trivial to reimplement with matthiasmullie/minify in a custom console command if you ever need to escape.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource