定制 taufik-nurrohman/kirby-minify 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

taufik-nurrohman/kirby-minify

Composer 安装命令:

composer require taufik-nurrohman/kirby-minify

包简介

CSS, HTML, JavaScript, JSON, PHP, and XML compressor for Kirby CMS.

README 文档

README

CSS, HTML, JavaScript, JSON, PHP, and XML compressor for Kirby CMS. This plugin has been tested with Kirby 5 with responses in the form of regular pages, CSS, JavaScript, JSON, and XML.

Just plug and play!

Installation

Tip

The your-plugin-name\ is the name you want to use for the plugin. The recommended plugin name is minify\, but you may want to use a different name for certain purposes. For example, Kirby does not have a hook priority feature, so the order in which hooks are executed depends entirely on the name of the plugin folder. This plugin should ideally be executed at the very end, so it is a good idea to give it a folder name that allows it to be positioned at the very end of the plugin list.

Download

Download the plugin via the download link and extract. Then put the extracted folder into the .\site\plugins\ folder of your Kirby project. If the plugins\ folder does not exist yet, create it first. The resulting folder structure should look like this:

.\
└── site\
    └── plugins\
        └── your-plugin-name\
            ├── index.php
            └── …

Git

If you use Git to version control your project, you can install plugins that are available from an online service like GitHub as a Git sub-module:

git submodule add https://github.com/taufik-nurrohman/kirby-minify.git site/plugins/your-plugin-name

Composer

This installation method works best if your project is managed via Composer as well. Then you can run the following command from the root of your project:

composer require taufik-nurrohman/kirby-minify

Options

Kirby configuration settings for plugins go into .\site\config\config.php. The configuration file contains a return statement with an array of configuration options:

<?php

return [
    'taufik-nurrohman.minify' => [
        'CSS' => [ /* … */ ],
        'HTML' => [
            // This will cause the HTML minifier to be disabled.
            'active' => false,
            'files' => [
                // This will disable the minification of CSS files embedded in HTML via the `<link>` element.
                'css' => false,
                // This will disable the minification of JavaScript files embedded in HTML via the `<script>` element.
                'js' => false,
                // This will disable the minification of SVG files embedded in HTML via the `<img>` element.
                'svg' => false
            ]
        ],
        'JS' => [
            'extensions' => [
                // Disable JavaScript minification if you have a dynamic JavaScript file that ends with `.mjs` extension.
                // By default, it will be enabled for dynamic files that end with both `.js` and `.mjs` extensions.
                'mjs' => false
            ]
        ],
        'JSON' => [
            'types' => [
                // Disable JSON minification if the current MIME type of the dynamic JSON file is `application/feed+json`.
                // Other dynamic JSON files with other MIME types will continue to be minified.
                'application/feed+json' => false
            ]
        ],
        // PHP minifier does nothing in general, unless you want to use its function (the `x\minify\p_h_p()` function) to
        // make some kind of PHP minifier in the control panel with the click of a button. Configuration options for this
        // minifier will have no effect.
        // 'PHP' => [],
        'XML' => [
            // Provide custom XML minification function to replace the default XML minification function (the `x\minify\x_m_l()` function).
            'f' => function (?string $value): ?string {
                return preg_replace('/>\s*</', '><', trim($value ?? ""));
            },
            // Provide custom XML file detection based on its content in case the current dynamic file extension is not
            // detected as XML file and the current dynamic file MIME type is also not detected as XML file.
            'test' => function (string $value) {
                return '<?xml' === trim(strtolower(strtok(trim($value), " \n\r\t")), '?');
            }
        ]
    ]
];

Notes

  1. Bug reports and feature requests related to Kirby CMS can be submitted here. Bug reports related to compression (e.g. compression of inline CSS and JavaScript code causes them to break) can be submitted here.
  2. The minify\ folder in this project contains the contents of the PHP Minify repository. Ideally, it should be set as a Git sub-module, however I decided to do a manual copy and paste of the files and folders to make it easier for users to install this plugin. Not everyone understands how to bring Git sub-modules into the project after doing a git clone. Git archive also won’t merge sub-modules automatically into the package.
  3. Don’t confuse the internal plugin name with the GitHub repository name (and also with the Composer package name). As explained in plugin best practices and custom plugin naming conventions, it is best to name the plugin without the kirby- prefix if you want the plugin to be listed properly in the official plugin repository later.

Tests

The PHP Minify project has it’s own tests. Here is an easy way you can do to run various tests specifically for this plugin:

  1. Create a .\content\my-content\test.txt file.
  2. Create a .\site\templates\test.css.php file and paste in some random CSS code there to test the CSS minifier in action on dynamic CSS file that can be accessed via http://127.0.0.1/my-content.css.
  3. Create a .\site\templates\test.js.php file and paste in some random JavaScript code there to test the JavaScript minifier in action on dynamic JavaScript file that can be accessed via http://127.0.0.1/my-content.js.
  4. Create a .\site\templates\test.json.php file and paste in some random JSON code there to test the JSON minifier in action on dynamic JSON file that can be accessed via http://127.0.0.1/my-content.json.
  5. Create a .\site\templates\test.xml.php file and paste in some random XML code there to test the XML minifier in action on dynamic XML file that can be accessed via http://127.0.0.1/my-content.xml.
  6. To test the HTML file minification, there is nothing you have to do. Simply go to your front-end site and view the source code! 😉

License

The PHP Minify library is licensed under the MIT License. Please consider donating 💰 if you benefit financially from this library.

taufik-nurrohman/kirby-minify 适用场景与选型建议

taufik-nurrohman/kirby-minify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 taufik-nurrohman/kirby-minify 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-12