voku / HtmlMin

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

Vue.js @shorthand attribute problem #18

Closed andrewckor closed 6 years ago

andrewckor commented 6 years ago

Hello, I am using your script "voku/html-min": "^3.0" for some time and it is working great. Recently we integrated vue.js into our laravel project and an unexpected bug appeared. After some investigation I realised that the minifier removes the vue js attributes that start with @.

Let me show you an example. This code: <select v-model="filter" @change="getGraphData" :class="['c-chart__label']" name="filter">

If you minify it through:

$htmlMin = new HtmlMin();
$htmlMin->doOptimizeViaHtmlDomParser(true);
$htmlMin->doRemoveWhitespaceAroundTags(true);
$htmlMin->doRemoveSpacesBetweenTags(true); 

return $htmlMin->minify($content);

You get this in the frontend: <select v-model="filter" :class="['c-chart__label']" name="filter">

That means that HtmlMin it strips out attributes that start with @. It shouldn't be a hard fix for you @voku.

Thanks.

andrewckor commented 6 years ago

It probably needs a @ somewhere here: https://github.com/voku/HtmlMin/blob/master/src/voku/helper/HtmlMin.php#L923-L930

voku commented 6 years ago

Thanks for the bug report. Fixed in version 3.0.3.

The problem is the PHP-Dom-Parser (DOMDocument), it can't handle the "@" in front of an attribute, so here is the hack for that... ;) https://github.com/voku/simple_html_dom/commit/2e18d6b866354432d6becdc6bcebcb3c61b94967

andrewckor commented 6 years ago

Thank you very much for your quick response. 👍

andrewckor commented 6 years ago

Hey @voku I updated to simple_html_dom 4.1.4 and html-min 3.0.3 and now this is what I get to the final html with the same settings:

<select v-model="filter" ____simple_html_dom__voku__at____change="getGraphData" :class="['c-chart__label']" name="filter">