承接 fpvcode/shrinkwrap 相关项目开发

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

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

fpvcode/shrinkwrap

Composer 安装命令:

composer create-project fpvcode/shrinkwrap

包简介

All-in-one HTML/JS/CSS code minifier.

README 文档

README

UKRAINE NEEDS YOUR HELP NOW!

On 24 February 2022, Russian President Vladimir Putin ordered an invasion of Ukraine by Russian Armed Forces.

Your support is urgently needed.

THANK YOU!

ShrinkWrap

Description

ShrinkWrap it's a wrapper for PHP minifiers of HTML/JS/CSS code. The main purpose of creating this wheel is the desire to have a more or less flexible tool for minifying ready-made HTML pages created by 3rd-party applications. Simply put - we submit an HTML page at the input, and at the output we have a page in which (optional):

  • HTML, inline JS-scripts and CSS-styles are minified.
  • JS and CSS files referenced by the page (except external ones) are minified (can also be combined) and cached, and the corresponding links are changed to point to the cache.

At the moment, ShrinkWrap uses the following tools:

Requirments

  • PHP >= 7.3.0

Installation

Use composer: composer require fpvcode/shrinkwrap.
Due to dependency requirements the package loaded by default requires PHP version 8.1.0. To download the package compatible with PHP 7.3.0, create a composer.json file with the following content:

{
    "config": {
        "vendor-dir": "vendor",
        "platform": {
            "php": "7.3"
        }
    }
}

Usage

use fpvcode\ShrinkWrap;

$shrinkwrap = new ShrinkWrap();

// Global options
$shrinkwrap->doMinifyHtml(true);        // Allow to minify HTML Code. Default value is `false`.
$shrinkwrap->doMinifyInlineJs(true);    // Allow to minify inline scripts. The scripts combine and append in the bottom of related parent tag (`head` or `body`). Default value is `false`.
$shrinkwrap->doMinifyInlineCss(true);   // Allow to minify inline styles. The styles combine and append in the bottom of related parent tag (`head` or `body`). Default value is `false`.
$shrinkwrap->doMinifyJs(true);          // Allow to minify and cache non-minified JS-files. Default value is `false`.
$shrinkwrap->doCombineJs(true);         // Allow to combine all JS-files into one. Depends on `->doMinifyJS(true)`. Default value is `false`.
$shrinkwrap->doMinifyCss(true);         // Allow to minify and cache non-minified JS-files. Default value is `false`.
$shrinkwrap->doCombineCss(true);        // Allow to combine all CSS-files into one. Depends on `->doMinifyCSS(true)`. Default value is `false`.
$shrinkwrap->doLog(true);               // Show some info in the browser console. Default value is `false`.
$shrinkwrap->assetDir('assets');        // Directory to store minified files cache. Default value is `__DIR__/assets`.

/* --------------------------------------------------------------------------*/
// Configure minify engines and set their native options.
/* --------------------------------------------------------------------------*/

// Voku HtmlMin minify options.
$voku_options = [
	'doOptimizeViaHtmlDomParser'                   => true,  // optimize html via "HtmlDomParser()"
	'doRemoveComments'                             => true,  // remove default HTML comments (depends on "doOptimizeViaHtmlDomParser(true)")
	'doSumUpWhitespace'                            => true,  // sum-up extra whitespace from the Dom (depends on "doOptimizeViaHtmlDomParser(true)")
	'doRemoveWhitespaceAroundTags'                 => true,  // remove whitespace around tags (depends on "doOptimizeViaHtmlDomParser(true)")
	'doOptimizeAttributes'                         => true,  // optimize html attributes (depends on "doOptimizeViaHtmlDomParser(true)")
	'doRemoveHttpPrefixFromAttributes'             => true,  // remove optional "http:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
	'doRemoveHttpsPrefixFromAttributes'            => true,  // remove optional "https:"-prefix from attributes (depends on "doOptimizeAttributes(true)")
	'doKeepHttpAndHttpsPrefixOnExternalAttributes' => true,  // keep "http:"- and "https:"-prefix for all external links
	'doMakeSameDomainsLinksRelative'               => [],    // make some links relative, by removing the domain from attributes (['example.com'])
	'doRemoveDefaultAttributes'                    => true,  // remove defaults (depends on "doOptimizeAttributes(true)" | disabled by default)
	'doRemoveDeprecatedAnchorName'                 => true,  // remove deprecated anchor-jump (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedScriptCharsetAttribute'     => true,  // remove deprecated charset-attribute - the browser will use the charset from the HTTP-Header, anyway (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedTypeFromScriptTag'          => true,  // remove deprecated script-mime-types (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedTypeFromStylesheetLink'     => true,  // remove "type=text/css" for css links (depends on "doOptimizeAttributes(true)")
	'doRemoveDeprecatedTypeFromStyleAndLinkTag'    => true,  // remove "type=text/css" from all links and styles
	'doRemoveDefaultMediaTypeFromStyleAndLinkTag'  => true,  // remove "media="all" from all links and styles
	'doRemoveDefaultTypeFromButton'                => false, // remove type="submit" from button tags
	'doRemoveEmptyAttributes'                      => true,  // remove some empty attributes (depends on "doOptimizeAttributes(true)")
	'doRemoveValueFromEmptyInput'                  => true,  // remove 'value=""' from empty <input> (depends on "doOptimizeAttributes(true)")
	'doSortCssClassNames'                          => true,  // sort css-class-names, for better gzip results (depends on "doOptimizeAttributes(true)")
	'doSortHtmlAttributes'                         => true,  // sort html-attributes, for better gzip results (depends on "doOptimizeAttributes(true)")
	'doRemoveSpacesBetweenTags'                    => true,  // remove more (aggressive) spaces in the dom (disabled by default)
	'doRemoveOmittedQuotes'                        => true,  // remove quotes e.g. class="lall" => class=lall
	'doRemoveOmittedHtmlTags'                      => true,  // remove ommitted html tags e.g. <p>lall</p> => <p>lall
];

$shrinkwrap->htmlEngineConfig('voku', $voku_options); // allows to customize the Voku HtmlMin minifier.

$html = '
<!DOCTYPE html>
<html dir="ltr" lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>HTML page</title>

    <script>
      function a() {
        let a = 0;
      }
    </script>

    <style>
      .class-a {
        border-radius: 4px;
      }
    </style>

    <script src="https://code.jquery.com/jquery-3.7.1.js" type="text/javascript"></script>
    <script src="js/a.js" type="text/javascript"></script>
    <script src="js/b.min.js" type="text/javascript"></script>

    <link href="https://cdn.usebootstrap.com/bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet" media="screen">
    <link href="css/a.css" rel="stylesheet" media="screen">
    <link href="css/b.min.css" rel="stylesheet" media="screen">
  </head>

  <body>
    <div>
      Test HTML
    </div>

    <!-- Comment -->
    <script>
      function b() {
        let b = 0;
      }
    </script>

    <script>
      function c() {
        let c = 0;
      }
    </script>

    <!-- Comment -->
    <style>
      .class-b {
        border-radius: 4px;
      }
    </style>
    <style>
      .class-c {
        border-radius: 4px;
      }
    </style>
  </body>


</html>';

$html = $shrinkwrap->output($html);

Minified output:

<!DOCTYPE html>
<html dir="ltr" lang="en"><head><meta charset="UTF-8"><meta content="width=device-width, initial-scale=1" name="viewport"><meta content="IE=edge" http-equiv="X-UA-Compatible"><title>HTML page</title><script src="//code.jquery.com/jquery-3.7.1.js"></script><link href="//cdn.usebootstrap.com/bootstrap/3.3.7/css/bootstrap.css" media="screen" rel="stylesheet"><script src="assets/4eb126993fd8e08ddf2c186bd95cd514.min.js"></script><link href="assets/55a39d42c37de2a6ca9617f70dfc2bfa.min.css" rel="stylesheet"><script>function a(){let a=0}</script><style>.class-a{border-radius:4px}</style><body><div> Test HTML </div><script>function b(){let b=0};function c(){let c=0}</script><style>.class-b{border-radius:4px}.class-c{border-radius:4px}</style></body></head></html>

Thanks

fpvcode/shrinkwrap 适用场景与选型建议

fpvcode/shrinkwrap 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「minify」 「minifier」 「HTML minify」 「css minify」 「js minify」 「PHP HTML minifier」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fpvcode/shrinkwrap 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fpvcode/shrinkwrap 我们能提供哪些服务?
定制开发 / 二次开发

基于 fpvcode/shrinkwrap 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-27