Loading repository data…
Loading repository data…
taufik-nurrohman / repository
CSS, HTML, JavaScript, JSON, PHP, and XML compressor for Kirby CMS.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
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!
[!TIP]
The
your-plugin-name\is the name you want to use for the plugin. The recommended plugin name isminify\, 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 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
└── …
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
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
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")), '?');
}
]
]
];
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.kirby- prefix if you want the plugin to be listed properly in the
official plugin repository later.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:
.\content\my-content\test.txt file..\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..\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..\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..\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.The PHP Minify library is licensed under the MIT License. Please consider donating 💰 if you benefit financially from this library.