voku / HtmlMin

:clamp: HtmlMin: HTML Compressor and Minifier via PHP
MIT License
161 stars 22 forks source link

Sudden <head> insertion #19

Closed ObeeWanKenobee closed 6 years ago

ObeeWanKenobee commented 6 years ago

What is this feature about (expected vs actual behaviour)?

It sucks. If I do this.

Compress("
</script>
<script async src="cdnjs"></script>
");

Since I use a different package to compress js. It suddenly insert a tag at the top. Which breaks the behaviour of the whole document.

How can I reproduce it?

matthiasmullie/minify>=1.3.60 voku/html-min>=3.0.3

use voku\helper\HtmlMin;
use MatthiasMullie\Minify;

$minifier = new Minify\JS();
$htmlMin = new HtmlMin();

echo $htmlMin->minify("
<script defer>
");

echo $minifier->minify("
//some js code
");

echo $htmlMin->minify("
</script>
<script async src="some cdnjs"></script>
");

## Result will be:
<head><script defer>//some js</script><script async src=some cdnjs></script>

Does it take minutes, hours or days to fix?

Just remove the frikin autocomplete then we're done :D

Any additional information?

voku commented 6 years ago

Hi, I added some regex magic (https://github.com/voku/simple_html_dom/commit/8d9f33be46b9c3afdc107b8045ffaebb85e461d2#diff-c9aceb5e54e67d5f19805df3f679fb1bR450) for your "problem" ... but I think it's a really bad idea to use broken html for whatever you do with html.

PS: here is a example -> https://github.com/voku/HtmlMin/commit/a42d3a5804b3b463b99922cb618b735ad290829e#diff-468b8a043eb54ed31edbee53141c1512R460

ObeeWanKenobee commented 6 years ago

Thanks man @voku haven't tried the latest release but I will make another ticket soon as soon as I discover something that sucks :p I love your package. I also hope I can integrate this with laravel