</> Code The Pixel

CakePHP 4 HTML Minify Plugin

Asyraf Wahi Anuar - December 02, 2021

Estimated reading time: 59 seconds

The practice of reducing the amount of code and markup in your web pages and script files is known as minification. It is one of the most used strategies for reducing website load times and bandwidth utilisation. Minification enhances site performance and accessibility significantly, which immediately translates into a better user experience. It's also useful for consumers that reach your website via a restricted data plan and want to reduce their bandwidth use while surfing the web. To minify the CakePHP web application codes, HTML Minify Plugin can be used.

Repository URL: https://github.com/WyriHaximus/MinifyHtml

Download the plugin using composer:

composer require wyrihaximus/minify-html 

Load Plugin

// In src/Application.php
use Cake\Http\BaseApplication;
use WyriHaximus\MinifyHtml\Plugin as MinifyHtmlPlugin;
class Application extends BaseApplication {
    public function bootstrap()

        // Load the minify html plugin by class name

Load Helper
Load helper in .../src/View/AppView.php

public function initialize(): void

If the debug mode is 'true', it will not minify the HTML source code. You can disable debug mode from ...config/app_local.php

'debug' => filter_var(env('DEBUG', false), FILTER_VALIDATE_BOOLEAN),

That's all. Happy coding :)

Cite this article (APA 6th Edition)

CakePHP 4 Print PDF Using CakePDF
May, 17 2020
CakePHP 4 Authentication Using Auth...
May, 14 2020
CakePHP 4 Sending Email
February, 01 2022
CakePHP 4 jQuery Date Time Picker
October, 01 2018
CakePHP 4 Export To CSV
May, 29 2020
CakePHP 4 Authentication Using...
May, 11 2020
CakePHP 4 Find, Sort & Count
June, 02 2020
Sharing Link
Click the icon to share