Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostHTML limitations for HTML minifying #99

Open
maltsev opened this issue Oct 11, 2020 · 3 comments
Open

PostHTML limitations for HTML minifying #99

maltsev opened this issue Oct 11, 2020 · 3 comments

Comments

@maltsev
Copy link
Member

maltsev commented Oct 11, 2020

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?

@SukkaW
Copy link
Contributor

SukkaW commented Oct 11, 2020

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.

@SukkaW
Copy link
Contributor

SukkaW commented Oct 12, 2020

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.

@SukkaW
Copy link
Contributor

SukkaW commented Oct 12, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants