sensiolabs/minify-bundle
Composer 安装命令:
composer require sensiolabs/minify-bundle
包简介
Assets Minifier (CSS, JS) for Symfony & Minify integration in Asset Mapper
README 文档
README
composer require sensiolabs/minify-bundle
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).
See transfer comparison (gzip)
| File | Original | Minified | Ratio | Gain | Compression |
|---|---|---|---|---|---|
| autoComplete.js | 5.59 KB | 2.68 KB | 47.96% | 52.04% | 🟩🟩🟩🟩🟩⬜️⬜️⬜️⬜️⬜️ |
| bootstrap.js | 29.92 KB | 12.58 KB | 42.06% | 57.94% | 🟩🟩🟩🟩🟩🟩⬜️⬜️⬜️⬜️ |
| video.js | 538.83 KB | 202.62 KB | 37.61% | 62.39% | 🟩🟩🟩🟩🟩🟩⬜️⬜️⬜️⬜️ |
| w3c.org.js | 10.44 KB | 5.89 KB | 56.45% | 43.55% | 🟩🟩🟩🟩⬜️⬜️⬜️⬜️⬜️⬜️ |
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 |
See transfer comparison (gzip)
| File | Original | Minified | Ratio | Gain | Compression |
|---|---|---|---|---|---|
| autoComplete.css | 1.08 KB | 0.89 KB | 82.41% | 17.59% | 🟩🟩⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️ |
| bootstrap.css | 33.56 KB | 28.94 KB | 86.08% | 13.92% | 🟩⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️ |
| video-js.css | 13.14 KB | 12.72 KB | 96.79% | 3.21% | 🟩⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️⬜️ |
| w3c.org.css | 21.98 KB | 13.65 KB | 62.13% | 37.87% | 🟩🟩🟩🟩⬜️⬜️⬜️⬜️⬜️⬜️ |
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
How to install without Symfony Flex
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require sensiolabs/minify-bundle
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php file of your project:
// config/bundles.php return [ // ... Sensiolabs\MinifyBundle\SensiolabsMinifyBundle::class => ['all' => true], ];
Depending on your deployment process, you might want to enable the bundle only in the desired environment(s).
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.
sensiolabs/minify-bundle 适用场景与选型建议
sensiolabs/minify-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 157.15k 次下载、GitHub Stars 达 57, 最近一次更新时间为 2024 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「assets」 「css」 「JS」 「minify」 「minifier」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sensiolabs/minify-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sensiolabs/minify-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sensiolabs/minify-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
The bundle for easy using json-rpc api on your project
Bundle Symfony DaplosBundle
Tool for loading or deploying CSS and JS files into web pages
统计信息
- 总下载量: 157.15k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 57
- 点击次数: 34
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-18