Open samouri opened 4 years ago
I like where your head's at. :)
A less ambitious version 0 of this could be to add i-amphtml-binding
attribute to all elements with a binding attribute to remove the cost of TreeWalker
.
A less ambitious version 0 of this could be to add
i-amphtml-binding
attribute to all elements with a binding attribute to remove the cost of TreeWalker.
I'd love for us improve this! We can use both a cache transform and AmpOptimizer to accomplish.
@jridgewell to write up an idea about detached iframes
summary
amp-bind is one of the most widely used methods for enabling interactivity in AMP pages. On low-end devices, it can take ~1.2s to initialize. This is largely due to the cost of starting up the webworker and parsing all of the bind expressions on the page.
Lately, I've been wondering if it could be possible for us to move some of this work to the AMP Optimizer.
assumption The vast majority of documents do not use mustache interpolation within their bind expressions. Since mustache rendering is done at runtime, they would be impossible to precompute.
optimization
We can skip expression parsing (and even downloading the parser) by computing the ASTs for each expression on the page in the AMP Optimizer. We can place a map from expression string to AST in an inline script tag on the page, with a verifiable/validatable hash.
TODOs:
[ ] measure how many bytes would be saved by not including the bind parser
Does this idea make any sense? cc @choumx