WyriHaximus / HtmlCompress

MIT License
77 stars 17 forks source link

HTML compress problem #166

Open JanaLEE opened 1 year ago

JanaLEE commented 1 year ago

Hi

I tried to minify HTML using the WyriHaximus/HtmlCompress module. The original HTML is as follows:

<!doctype html>
<!--[if lt IE 9]><html class="no-js no-svg ie lt-ie9 lt-ie8 lt-ie7" lang="en-US"> <![endif]-->
<!--[if IE 9]><html class="no-js no-svg ie ie9 lt-ie9 lt-ie8" lang="en-US"> <![endif]-->
<!--[if gt IE 9]><!--><html class="no-js no-svg" lang="en-US"> <!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta name="description" content="" />
</head>
<body data-template="base.twig">
    <header class="header">
        <div class="wrapper">
            <h1 class="hdr-logo" role="banner"></h1>
            <nav id="nav-main" class="nav-main" role="navigation">
            </nav>
            <!-- #nav -->
        </div>
    </header>
    <section id="content" role="main" class="content-wrapper">
        <div class="wrapper ">
        </div>
        <!--/wrapper-->
    </section>

    <footer id="footer">
    </footer>
<script>
/* <![CDATA[ */
var vars = {};
/* ]]> */
</script>
</body>
</html>

PHP \WyriHaximus\HtmlCompress\Factory::constructSmallest()->compress($output)

However, the order of the output HTML after minification is incorrect. The field var vars={}; , which originally appeared end of HTML, is now placed before DOCTYPE. The output HTML is as follows:

var vars={};<!DOCTYPE html><!--[if lt IE 9]><html class="no-js no-svg ie lt-ie9 lt-ie8 lt-ie7" lang="en-US"> <![endif]--><!--[if IE 9]><html class="no-js no-svg ie ie9 lt-ie9 lt-ie8" lang="en-US"> <![endif]--><!--[if gt IE 9]><!--><html class="no-js no-svg" lang=en-US> <!--<![endif]--> <head><meta charset=UTF-8><meta content="" name=description> <body data-template=base.twig><header class=header><div class=wrapper><h1 class=hdr-logo role=banner></h1> <nav class=nav-main id=nav-main role=navigation></nav></div> </header> <section class=content-wrapper id=content role=main><div class=wrapper></div> </section> <footer id=footer></footer> <script>var vars={}</script>

What could be the problem?

JanaLEE commented 1 year ago

I remove and reinstall wyrihaximus/html-compress, the problem is fixed...

WyriHaximus commented 1 year ago

However, the order of the output HTML after minification is incorrect. The field var vars={}; , which originally appeared end of HTML, is now placed before DOCTYPE. The output HTML is as follows:

var vars={};<!DOCTYPE html><!--[if lt IE 9]><html class="no-js no-svg ie lt-ie9 lt-ie8 lt-ie7" lang="en-US"> <![endif]--><!--[if IE 9]><html class="no-js no-svg ie ie9 lt-ie9 lt-ie8" lang="en-US"> <![endif]--><!--[if gt IE 9]><!--><html class="no-js no-svg" lang=en-US> <!--<![endif]--> <head><meta charset=UTF-8><meta content="" name=description> <body data-template=base.twig><header class=header><div class=wrapper><h1 class=hdr-logo role=banner></h1> <nav class=nav-main id=nav-main role=navigation></nav></div> </header> <section class=content-wrapper id=content role=main><div class=wrapper></div> </section> <footer id=footer></footer> <script>var vars={}</script>

What could be the problem?

Honestly? No clue, I'm mainly wrapping other packages to handle parts of this. The var vars={} is still at the end tho, not sure why it also ended up at the front.

I remove and reinstall wyrihaximus/html-compress, the problem is fixed...

And this is the part that scares me, this shouldn't happen. Unless one of the dependencies also got updated at the same time.

JanaLEE commented 1 year ago

I have no idea why that happened. Fortunately, I reinstall it and problem solved then.

WyriHaximus commented 1 year ago

No worries, it is probably a glitch, and if it happens again I'll dive into it.

JanaLEE commented 10 months ago

Hi

I found another question, the html below

``

will be minified into

`` which the `<\/div>` is goint to cause html output wrong. I replace the `<\/` to `

WyriHaximus commented 9 months ago

Hey @JanaLEE, been looking into this and it might be an upstream issue. Doing some final checks to confirm that before opening an issue there, will also tag you in it. Problem seems to be that I get the <\/div> before I skip the minimization for it.