承接 codealfa/minify 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codealfa/minify

最新稳定版本:2.1.0

Composer 安装命令:

composer require codealfa/minify

包简介

An extremely fast PHP based minification library for Javascript, CSS, Html and Json scripts using Regex Parsing

README 文档

README

An extremely fast PHP based minification library for Javascript, CSS, Html and Json scripts using Regex Parsing

Installation

Run the following command to use the library in your projects:

composer require codealfa/minify

Basic Usage

You can use any of the minifiers in the following way:

use CodeAlfa\Minify\Js;

$sMinifiedJs = Js::optimize($sOriginalJs);

Html Minifier Options

The HTML minifier takes the following options:

  • cssMinifier (default null): Callback function to minify the contents of in-page <style> elements.
  • jsMinifier (default null): Callback function to minify the contents of in-page <script> elements.
  • jsonMinifier (default null): Callback function to minify the contents of in-page json contents. The Html Minifer will inspect the type attribute of script contents to determine if it's javascript or json.
  • minifyLevel (default 0): Determine the minification level of the HTML. Possible values are:
    • 0: Runs of whitespace outside elements are reduced to one whitespace, if a line feed is included it will be preserved. (HTML comments are not removed). In-page scripts and styles are minified if callback functions were provided.
    • 1: HTML comments are removed, along with whitespaces around block elements. Unnecessary whitespaces inside elements and around attributes are removed.
    • 2: Redundant attributes eg., type="text/javascript" are removed. Quotes are removed from selected attributes if the isHtml5 option is set to true.
  • isXhtml (default false): HTML content treated as XHTML1.0. In-page javascript content with characters that needs escaping in XML will be surrounded by /*<![CDATA[*/ and /*]]>*/
  • isHtml5 (default false): If set to true then when minifyLevel is set to 2, quotes are removed from attibutes if they don't contain characters that necessitates quoting.

Example:

use CodeAlfa\Minify\Html;

$aOptions = array(
    'cssMinifier' => array('CodeAlfa\Minify\Css', 'optimize'),
    'jsMinifier'  => array('CodeAlfa\Minify\Js', 'optimize'),
    'minifyLevel' => 2,
    'isHtml5'     => true
);

$sMinifiedHtml = Html::optimize($sOriginalHtml, $aOptions);

License

GPL-3.0 or later

统计信息

  • 总下载量: 295
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: JavaScript

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-10-12