posthtml / htmlnano

Modular HTML minifier, built on top of the PostHTML
https://htmlnano.netlify.app
MIT License
253 stars 29 forks source link

Ideas for minifiers #12

Open maltsev opened 8 years ago

maltsev commented 8 years ago
voischev commented 8 years ago

remove \n \t and ect

tree.match(/^\n\s*$/, () => '');

https://github.com/posthtml/project-stub/blob/master/gulpfile.js#L14-L18

maltsev commented 8 years ago

@voischev the module collapseWhitespace does that. Or did you find some error?

stevenvachon commented 8 years ago

The biggest thing for me is to split out to separate plugins for individual test suites:

@maltsev normalize-html-whitespace is the most accurate. @voischev, the key is to normalize, not strip as to preserve rendered appearance.

maltsev commented 8 years ago

@stevenvachon, first of all, thank you for new plugin ideas! I'll consider splitting out the modules to separate plugins. But it'll be much harder for me to maintain a few dozens small plugins (documentation, infrastructure) instead of one htmlnano.

stevenvachon commented 8 years ago

No problem. It's definitely more work to create separate projects, at least initially. Once created, it will make dealing with tests much easier because there're fewer of them and they're all very specific to one feature. This is how cssnano and cssnext are designed.

maltsev commented 8 years ago

@stevenvachon, I agree with you. I'm also trying to write the modules and the tests as separated as possible, so it'll be easy to split off them later.

stevenvachon commented 8 years ago

Whitespace within attributes containing space-separated lists can also be normalized:

<a href="#" class="class1   class2 " rel=" external    nofollow ">link</a>

->

<a href="#" class="class1 class2" rel="external nofollow">link</a>
stevenvachon commented 8 years ago
  1. switch between ' and " (per attribute) as attribute value encapsulators to find which produces the smallest output (due to any necessary commenting: attr='blah \'blah\'' vs attr="blah 'blah'")
  2. remove quotes on qualifying attributes (attr=single_value)
maltsev commented 8 years ago

@stevenvachon, thanks! I've created an issue for your first idea: #27 An issue for the second one is already there: #6

stevenvachon commented 8 years ago

svgo for inline svg

stevenvachon commented 8 years ago
  1. Remove optional closing tags such as </html>, </head>, </body>, </option>, </p>, </thead>, </tbody>, </tfoot>, </tr>
  2. remove optional opening tags such as <html>, <head>, <body>
stevenvachon commented 8 years ago

Strip HTML from content within <title></title> tags as browsers and search engines will ignore it anyway.