fahlisaputra / laravel-minify

Minify your blade views, html, css and obfuscate js files on the fly. Lightweight minifier for your Laravel project.
MIT License
70 stars 14 forks source link

Can not wrok with Chinese #22

Open vagh opened 6 months ago

vagh commented 6 months ago

Hello, this package doesn't seem to support Chinese compression.

image
Cheesper commented 4 months ago

Russian too

Cheesper commented 4 months ago

Tried to fix Minifier.php, but all text converted at symbols like "\К\а\р\т\и\н\к\и" @static::$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NODEFDTD | LIBXML_SCHEMA_CREATE);

cheusbeats commented 2 months ago

Tried to fix Minifier.php, but all text converted at symbols like "Картинки" @static::$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NODEFDTD | LIBXML_SCHEMA_CREATE);

Russian you can fix by changing two methods handle and loadDom in Minifier.php

protected function loadDom(string $html, bool $force = false)
    {
        if (static::$dom instanceof DOMDocument) {
            if ($force) {
            } else {
                return;
            }
        }

        static::$dom = new DOMDocument();
        static::$dom->encoding = 'UTF-8';
        @static::$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NODEFDTD | LIBXML_SCHEMA_CREATE);
    }
public function handle(Request $request, Closure $next)
    {
        $response = $next($request);

        if (!$this->shouldProcessMinify($request, $response)) {
            if (!(static::$dom instanceof DOMDocument)) {
                return $response;
            }
        }

        $html = $response->getContent();

        $html = self::replaceDirectives($html);

        $this->loadDom($html);

        $minifiedHtml = $this->apply();
        $minifiedHtml = html_entity_decode($minifiedHtml, ENT_QUOTES | ENT_HTML5, 'UTF-8');

        return $response->setContent($minifiedHtml);

    }