icedevelopment / compressor-bundle
HTML 压缩和优化工具包
0.2
2016-01-13 09:44 UTC
Requires
- php: >=5.3.3
- symfony/symfony: >2.2.0
This package is auto-updated.
Last update: 2024-09-20 02:09:32 UTC
README
要求
- Symfony 2 (>= 2.2)
安装
- 将此包包含在您的 composer.json 中
$ php composer.phar require icedevelopment/compressor-bundle dev-master
在您的 AppKernel.php 中启用此包
<?php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
...
new Kcs\CompressorBundle\KcsCompressorBundle(),
...
);
...
}
}
配置
您可以通过更改 config.yml 中的这些标志之一来启用或禁用保存器和压缩器
kcs_compressor: enabled: true # Set to false to disable the compressor compress_html: true # Enable HTML optimizations preserve_line_breaks: true # Enable the line breaks preservation remove_comments: true # Remove HTML comments while compressing remove_extra_spaces: true # Remove extra spaces in HTML compress_js: true # Enable inline js compression compress_css: true # Enable inline css compression skip_block_tag: '\#\#\#' # Allow to change skipBlockTag, to make it compatible with twig
如果启用了内联 JS(或 CSS)压缩,则必须指定要使用的压缩器
kcs_compressor: js_compressor: none # Can be none (disabled), yui or custom css_compressor: none # Can be none (disabled), yui or custom
您可以指定内联 JS 和 CSS 压缩器的 custom
类。使用 js_compressor_class
和 css_compressor_class
设置来指定必须使用的类。
自定义内联压缩器类必须实现 Kcs\CompressorBundle\Compressor\InlineCompressorInterface
接口,并导出一个接受未压缩内容作为参数并返回压缩块的 compress
公共函数。
YUI 压缩器
如果使用 YUI 压缩器,则必须在 yui_jar
设置中指定 YUI jar 文件的存储位置。您还可以通过修改 java_path
设置来更改 Java 可执行文件路径。如果未指定,则默认为 /usr/bin/java
。