kcs / compressor-bundle
HTML 压缩和优化包
v0.1
2015-05-27 08:24 UTC
Requires
- php: >=5.3.3
- symfony/symfony: >2.2.0
This package is auto-updated.
Last update: 2024-08-29 04:30:59 UTC
README
要求
- Symfony 2 (>= 2.2)
安装
- 在您的 composer.json 中包含此包
$ php composer.phar require kcs/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
如果启用了内联 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
。