-
Notifications
You must be signed in to change notification settings - Fork 644
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
Server-rendered HTML minification #1432
Comments
[moved into own issue] |
Some updated thoughts on my proposals above:
While
After some more investigation, these two seem like they have the best reduction:effort ratio. Lotta
This one seems like the most difficult, but it also can pay off the most. I’m undecided. |
@tigt Hey, just been looking through this issue and a few MR's around the unquoted attributes. We upgraded to latest and tracked our issues to the unquoted attributes. I don't feel like this requires an issue, but let me know if you prefer it in that format. Is there a way to remove this behaviour or toggle it on/off? We use a HTML to PDF converter, where our HTML is generated by Marko, and our PDF converter that we are using doesn't parse anything with unquoted attributes due to the type of spec it adheres to so right now we are stuck at 4.20.2 for the foreseeable. |
@alexnewmannn I don’t believe as it stands this feature has a config toggle. (I didn’t implement it, just yammered about it in this issue.) For a fix that would solve your problem right now, you could round-trip the HTML Marko produces into and then out of a HTML parsing library, then pass that to your PDF converter. To do that with the import { parse, serialize } from 'parse5'
const minifiedHtml = markoTemplate.render(…) // or however you do it
const normalizedHtml = serialize(parse(minifiedHtml)) |
Removed the stuff about smaller internal ID encodings since any element index between 30 and ~50 would encode as forbidden Latin-1 Supplement control characters. (Aw beans.) |
Ran some of the remaining suggestions against the eBay home page:
|
Description
Marko’s compilation to server-side templates could perform provably-safe HTML minification during compilation. (Runtime minification is probably too expensive to be worth it.)
Why
Perf matters! Running Marko’s current home page through kangax’s minifier saves 2,551 bytes. Not too bad after compression, but it’s still overhead, and fewer characters speed up parsing.
Existing HTML minifiers can be plugged into a Marko app’s render pipeline, but they require buffering the stream, defeating any performance improvements.
Possible Implementation & Open Questions
In development mode, probably don’t bother running this compilation step. But in production…
style
class
,rel
, and other TokenLists/similar<pre>
,marko-preserve-whitespace
<head>
or<body>
</body></html>
, consecutive<p>
s,</option>
since</select>
autocloses itmethod="get"
,<input type="text">
,<script type="text/javascript">
, etc. — this would also make rendering client-side slightly more efficientTruthy booleans should omitMisc perf improvements #1535 ✅=""
Literals not containing whitespace should omit quotesperf: minify runtime comments, remove unnecessary attr quotes #1557 ✅Literals containingperf: minify runtime comments, remove unnecessary attr quotes #1557 ✅"
or'
' should use the other delimiter for the valueIf the attribute value is known not to stringify with forbidden characters (perf: minify runtime comments, remove unnecessary attr quotes #1557 ✅Number
, for example), it should omit quotesEverything else should fall back to wrapping double quotesperf: minify runtime comments, remove unnecessary attr quotes #1557 ✅→
should be dereferenced>
outside opening tag contexts=
outside attribute values<
→<
(pretty sure only<
and>
qualify)'
→'
, since hex numbers are only more compact for characters we’re already decoding"
→"
href
,src
,srcset
) into relative URLs:scoped
identifiers and<!--M#…-->
boundary comments with something more space-efficient than decimal, likenumber.toString(36)
<path></path>
→<path />
Is this something you're interested in working on?
Yes
The text was updated successfully, but these errors were encountered: