Welcome Guest, Not a member yet? Register   Sign In
plz, show me to run minify in codeigniter 4
#1

i read  to minify codeigniter 4 on https://gitlab.irbidnet.com/-/snippets/3 , but i dont understand  and dont work
go to app/Config/Events.php
PHP Code:
//minify html output on codeigniter 4
if (ENVIRONMENT !== 'development')
    {
    Events::on('post_controller_constructor', function () {


        while (ob_get_level() > 0)
        {
            ob_end_flush();
        }

        ob_start(function ($buffer) {
            $search = array(
                '/\n/',      // replace end of line by a <del>space</del> nothing , if you want space make it down ' ' instead of ''
                '/\>[^\S ]+/s',    // strip whitespaces after tags, except space
                '/[^\S ]+\</s',    // strip whitespaces before tags, except space
                '/(\s)+/s',    // shorten multiple whitespace sequences
                '/<!--(.|\s)*?-->/' //remove HTML comments
            );

            $replace = array(
                '',
                '>',
                '<',
                '\\1',
                ''
            );

            $buffer preg_replace($search$replace$buffer);
            return $buffer;
        }); 

can someone demo this code?
thank you very much
Reply


Messages In This Thread
plz, show me to run minify in codeigniter 4 - by startup - 11-24-2022, 07:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB