PWA: API for shadow dom streaming#9495
Conversation
examples/pwa/pwa.js
Outdated
|
|
||
| // Fetch. | ||
| const url = this.resolveUrl_(path); | ||
| const url = this.resolveUrl_(path) + '?stream=1000'; |
There was a problem hiding this comment.
Do you want to keep this the default? If yes, please comment on it.
| Using the streaming API: | ||
| ```javascript | ||
| const shadowDoc = AMP.attachShadowDocAsStream(hostElement, url, options); | ||
| fetch(url).then(response => { |
There was a problem hiding this comment.
The real example here is the one including the polyfill above, right?
Does it make sense to provide a helper for stream fetching?
There was a problem hiding this comment.
Possibly. I'll consider for a follow up PR. This API, however, looks the best to me so far on the generic level.
| let transferCount = 0; | ||
| while (inputBody.firstChild) { | ||
| transferCount++; | ||
| targetBody.appendChild(inputBody.firstChild); |
There was a problem hiding this comment.
I don't fully understand how this works. Does it only stream direct children of body? What if they aren't closed yet?
There was a problem hiding this comment.
Correct. That's a neat part of https://jakearchibald.com/2016/fun-hacks-faster-content/ and https://html.spec.whatwg.org/multipage/syntax.html#stack-of-open-elements. When you move an "open" node, the parser continues to stream into it.
cramforce
left a comment
There was a problem hiding this comment.
I think we should iterate on this a bit, but lets get it in.
|
All of this is epic win. |
examples/pwa/pwa.js
Outdated
| // but, TMK, these are not supported anywhere yet. | ||
| const reader = response.body.getReader(); | ||
| const decoder = new TextDecoder(); | ||
| function readChunk() { |
There was a problem hiding this comment.
Looks like we can hoist this closure outside of readChucnk
| xhr.onreadystatechange = null; | ||
| reject(new Error(`Unknown HTTP status ${xhr.status}`)); | ||
| return; | ||
| } |
|
Out of curiosity, how is the impact of this PR being measured? |
|
@jakearchibald This is pretty experimental at this time. But bunch of tests I ran showed a big incremental speed up. |
This PR supersedes #9428. It creates an API for shadow doc streaming via the StreamWriter interface. It's still marked as experimental until I fully measure impact. At that point, the old codepath will be re-implemented via the streaming API.
In the end, the set of changes is very modest, but lots of tests.
Closes #9491.
Related to #9490.
/cc @bjalford