yeoman / generator-polymer

Scaffold out a Polymer project
http://polymer-project.org
926 stars 150 forks source link

htmlmin not working #53

Closed trevordmiller closed 10 years ago

trevordmiller commented 10 years ago

The htmlmin task in the Gruntfile.js only produces expanded html by default, which is essentially not minified. I would imagine that this was a mistake and that the htmlmin task should be set to expand: false and the options that have been commented out should be added back in?

robdodson commented 10 years ago

I was actually looking into this yesterday. The htmlmin task is super buggy (the collapse whitespace flag can and will delete your whole file). What I found was that compressing a really really big vulcanized file (think the entire Polymer element set) only produced ~1kb in savings. And it seems like it does a pretty sketchy job of compressing things (read: inconsistent) so I may actually remove it from the build entirely.

trevordmiller commented 10 years ago

@robdodson Gotcha. That makes sense. I didn't realize that minifying your HTML had so little savings!

robdodson commented 10 years ago

Neither did I. I'm going to test it a few more times but a larger concern for me is if htmlmin starts breaking a vulcanized file or causing hard to debug issues for people. That it already produces really inconsistent output leads me to think that it could be a pain down the line. On Jul 25, 2014 9:44 AM, "Trevor D. Miller" notifications@github.com wrote:

@robdodson https://github.com/robdodson Gotcha. That makes sense. I didn't realize that minifying your HTML had so little savings!

— Reply to this email directly or view it on GitHub https://github.com/yeoman/generator-polymer/issues/53#issuecomment-50174379 .

robdodson commented 10 years ago

After playing with this some more it looks like htmlmin actually does produce significantly smaller output, however it seems to be blowing up on lines like this:

<div id="mainContainer" flex?="{{mode !== 'cover'}}" on-scroll="{{scroll}}">

vulcanize (by way of cheerio) is encoding the apostrophes in those lines and that breaks htmlmin

<div id="mainContainer" flex?="{{mode !== &apos;cover&apos;}}" on-scroll="{{scroll}}">

Related issue: https://github.com/cheeriojs/cheerio/issues/319

I'll try to fold it back in when I can get the cheerio issues sored

sindresorhus commented 10 years ago

You might want to try out https://github.com/sindresorhus/grunt-minify-html, it uses Minimize which uses an actual HTML parser.

trevordmiller commented 10 years ago

@robdodson Also, if you go the Gulp route, the Web Starter Kit uses "gulp-minify-html"...https://www.npmjs.org/package/gulp-minify-html

robdodson commented 10 years ago

I dropped htmlmin in favor of minifyHTML