sensiolabs/minify-bundle
Assets Minifier (CSS, JS) for Symfony & Minify integration in Asset Mapper
Maintainers
Package info
github.com/sensiolabs/minify-bundle
Type:symfony-bundle
pkg:composer/sensiolabs/minify-bundle
Requires
- php: >=8.1
- psr/log: ^2|^3
- symfony/filesystem: ^6.4|^7.0|^8.0
- symfony/http-client-contracts: ^3.5
- symfony/process: ^6.4|^7.0|^8.0
Requires (Dev)
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^10.5
- symfony/asset-mapper: ^6.4|^7.0|^8.0
- symfony/console: ^6.4|^7.0|^8.0
- symfony/framework-bundle: ^6.4|^7.0|^8.0
- symfony/http-client: ^6.4|^7.0|^8.0
- symfony/http-kernel: ^6.4|^7.0|^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT cf6462fbbd7883367c6ee1f02424e93a3df79384
- Simon AndrΓ© <smn.andre.woop@gmail.com>
- SensioLabs
README
π SensioLabs Minify Bundle for Symfonycomposer require sensiolabs/minify-bundle
π PHP Version
π CI
π Release
π Packagist Downloads
π License
Minify integration
SensioLabs Minify Bundle integrates Minify into Symfony Asset Mapper.
Asset Minifier
β
Minify CSS and JS files, remove whitespace, comments, and more..
π Reduces the size of your assets by up to 70% (see metrics below).
π Improves the loading time of your website, and the user experience.
Asset Mapper
π― Automatically minify assets during the build process.
π¦ Stores minified assets in the Symfony cache.
πΏ Download the Minify binary automatically from Github.
Minification
JavaScript
| File | Original | Minified | Ratio | Gain | Compression | Time |
|---|---|---|---|---|---|---|
| autocomplete.js | 19.88 KB | 9.17 KB | 46.13% | 53.87% | π©π©π©π©π©β¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈ | 8 ms |
| bootstrap.js | 145.40 KB | 62.20 KB | 42.76% | 57.24% | π©π©π©π©π©π©β¬οΈβ¬οΈβ¬οΈβ¬οΈ | 10 ms |
| video.js | 2.35 MB | 690.10 KB | 29.33% | 70.67% | π©π©π©π©π©π©π©β¬οΈβ¬οΈβ¬οΈ | 42 ms |
| w3c.org js | 43.39 KB | 19.23 KB | 44.34% | 55.66% | π©π©π©π©π©π©β¬οΈβ¬οΈβ¬οΈβ¬οΈ | 6 ms |
Even gzip compression is more efficient on minified assets (see metrics below).
CSS
| File | Original | Minified | Ratio | Gain | Compression | Time |
|---|---|---|---|---|---|---|
| autocomplete.css | 3.09 KB | 2.51 KB | 81.33% | 18.67% | π©π©β¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈ | 2 ms |
| bootstrap.css | 281.05 KB | 231.89 KB | 82.51% | 17.49% | π©π©β¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈ | 9 ms |
| video-js.css | 53.37 KB | 47.06 KB | 88.24% | 11.76% | π©π©β¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈ | 4 ms |
| w3c.org css | 111.44 KB | 70.37 KB | 63.17% | 36.83% | π©π©π©π©β¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈβ¬οΈ | 5 ms |
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
With Symfony Flex
Open a command console, enter your project directory and execute:
composer require sensiolabs/minify-bundle
Without Symfony Flex
Usage
If you use AssetMapper, run the following command to minify all the assets:
php bin/console asset-map:compile
This command is usually run when serving assets in production and the SensioLabs Minify Bundle will hook into it to minify all assets while copying them.
Command Line
You can also minify assets manually with the command line. First, make sure that the binary file used to minify assets is properly installed in your computer:
php bin/console minify:install
Then, run the following command to minify assets:
# this outputs the result in the console php bin/console minify:asset css/main.css # this will write the output into the 'main.min.css' file # (the given output file is created / overwritten if needed) php bin/console minify:asset css/main.css css/main.min.css
Configuration
AssetMapper
# config/packages/sensiolabs_minify.yaml sensiolabs_minify: asset_mapper: # you can minify only CSS files, only JS files or both types: css: true # (default: true) js: true # (default: true) # a list of assets to exclude from minification (default: []) # the values of the list can be any shell wildcard patterns ignore_paths: - 'admin/*' - '*.min.js' # whether to exclude the assets stored in vendor/ from minification; # these assets are usually pre-minified, so it's common to exclude them ignore_vendor: true # (default: true)
Minify Binary
Local binary
The minification is performed by a binary file that can be installed on your computer/server or downloaded automatically by the bundle. This is the default configuration used by the bundle:
# config/packages/sensiolabs_minify.yaml sensiolabs_minify: # ... minify: # this disables the usage of local binaries local_binary: false # if TRUE, the bundle will download the binary from GitHub download_binary: '%kernel.debug%' # the local path where the downloaded binary is stored download_directory: '%kernel.project_dir%/var/minify' # the Minify version to download (default: null for latest) version: null
You can customize this configuration to use a local binary:
# config/packages/sensiolabs_minify.yaml sensiolabs_minify: # ... minify: # set it to 'auto' to let the bundle try to find the location of the binary local_binary: 'auto' # you can also define the path to the binary explicitly, but this won't work # if you run the application in multiple servers with different binary locations local_binary: "/usr/local/bin/minify"
Credits
Authors
- MinifyBundle: Simon AndrΓ© & SensioLabs
- Minify binary: Timo Dewolf
Acknowledgments
This bundle is inspired by the following projects:
- SassBundle from @SymfonyCasts
- BiomejsBundle from @Kocal
- TypeScriptBundle from @SensioLabs
Contributors
Special thanks to the Symfony community for their contributions and feedback.
License
The SensioLabs Minify Bundle is released under the MIT license.
