I'm imagining something which takes the following HTML+CSS:
...
Hello
lorem ipsum
dolor sit amet
And transforms it into this: Hello
However, it should not always inline the css styles, because sometimes that would cause the result to be larger than the original, like this:
...
Hello
lorem ipsum
dolor sit amet
Here, is shorter than
, so it should remain unchanged.
I'm not talking about tools like https://htmlcompressor.com/compressor/ which only remove whitespace, or gzip compression. What I want is something that understands the semantics of HTML+CSS and can intelligently inline iff that reduces the size of the resulting HTML file.
If you’re looking for a wider task, e.g. unused css class elimination, then start with webpack and its plugins.
1. Your HTML is never the heaviest part of a webpage unless the page is pure HTML without JavaScript, images, audio, video, or embeds.
2. Minification, compilation, etc. tends to obfuscate your code. This makes it hard to read if a newbie to the web wants to use "view source" to see how you make your pages so they can learn from you.
Add to this, the caching of the CSS file upon the first HTML file's use by the browser makes any css inlining in the HTML not worthwhile. The caching would save a lot more bandwidth each time the HTML files are accessed (by the same browser).
This combined with HTTP compression is far superior to any inlined HTML+CSS.