posthtml / htmlnano

Modular HTML minifier, built on top of the PostHTML

Home Page:https://htmlnano.netlify.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minify CSS class names and ids

fstanis opened this issue · comments

This can be done simply by calling posthtml-uglify inside minifyCss.

Bonus is that it can share the whitelist with uncss if we add uncss per #36.

Good idea! I guess it might break some pages, so it's better to add it to max preset.

Does posthtml-uglify take into account external styles? If not then we should do that on our side.

Does posthtml-uglify take into account external styles?

No, it only looks at <style> tags.

If not then we should do that on our side.

How would that work? Wouldn't that mean that htmlnano would have to modify files outside the HTML?

How would that work?

I see a few possible ways:

  • Ignore classes and IDs found in external CSS. Not sure how easy it'd be to parse them, though.
  • Rewrite names in external CSS. It seems a bit out of htmlnano's scope for me, though.
  • Disable minification at all if external CSS is found.

In an ideal case, we could implement all 3 options and let users configure that themselves how they want this minification work.

Ouch, completely forgot that this will break external stylesheets. That's a tricky problem to solve.

Disable minification at all if external CSS is found.

This seems like a good low-hanging fruit for a first version.

I'm also worried that posthtml-uglify seems unmaintained (at least based on PR / issue activity). Taking this into account, I'm now leaning more towards replicating similar functionality in htmlnano (or maybe forking the project?).

I'm also worried that posthtml-uglify seems unmaintained (at least based on PR / issue activity).

I think it's totally fine to use it. We can always switch htmlnano to a forked version if needed. We could also ask then if @Rebelmail are willing to transfer posthtml-uglify to posthtml namespace.

You may also want to consider posthtml-minify-classnames which still receives maintenance and has a few more improvements over posthtml-uglify?