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

PostHTML limitations for HTML minifying

maltsev opened this issue · comments

In #29 @SukkaW asked whether it's possible to remove closing tags in PostHTML since it'd produce an invalid HTML. Although I don't know the answer to that particular question, it raises a more important question.

PostHTML provides a very useful API and helps a lot in HTML processing, but we'll get to the point when not all minifications could be implemented due to its limitations (e.g., how it processed HTML and which transformations it supports). I see two possible solutions:

  • don't implement these minifications — optimal from the dev perspective (i.e., more clean and straightforward code), but not from the end-user perspective

  • implement them on top of PostHTML — the code would become messier and more complex, but HTML would get minified better.

Neither of them is good. So, what do you guys think?

commented

PostHTML is kind of an AST parser and manipulator. Basically, it receives HTML string, converts into an AST tree (which will be processed by PostHTML plugins), then PostHTML will re-build HTML string based on processed AST tree. Since PostHTML plugins like htmlnano can't have access to re-build HTML string based on processed AST tree, that means there is really nothing we can do on plugin side.

See also #6. In that feature request issue htmlnano failed to remove attribute quotes since those quotes are added and controlled by PostHTML.

commented

It would be helpful if PostHTML provides a way for plugins to control posthtml-render.

For example, for #6, if a user doesn't configure quoteAllAttributes at PostHTML side while enabling removeOptioinalQuotes at htmlnano side, htmlnano should be able to override quoteAllAttributes.

commented

posthtml/posthtml#335

An issue has been opened at PostHTML, to see if PostHTML Team willing to implement an API for plugins to control the behavior of posthtml-render.