htmlnano icon indicating copy to clipboard operation
htmlnano copied to clipboard

Minify CSS class names and ids

Open fstanis opened this issue 5 years ago • 6 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.

fstanis avatar Dec 27 '18 14:12 fstanis

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.

maltsev avatar Dec 27 '18 19:12 maltsev

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?

fstanis avatar Dec 28 '18 11:12 fstanis

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.

maltsev avatar Dec 31 '18 11:12 maltsev

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?).

fstanis avatar Jan 03 '19 11:01 fstanis

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.

maltsev avatar Jan 03 '19 21:01 maltsev

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

polarathene avatar Apr 27 '21 01:04 polarathene