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

[DO NOT MERGE] Implement iterator template rendering & promise values for HTML rendering #30

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nateps
Copy link
Contributor

@nateps nateps commented Dec 4, 2019

Initial attempt at implementing delayed/incremental HTML rendering.

Consists of two new features:

  1. Returning a promise value causes .get() rendering to return a promise. Thus, HTML rendering can support use of async values in addition to synchronous values with minimal additional overhead.
  2. Implement iterator & iterable APIs that support the introduction of yield points in templates, inspired by JavaScript's yield keyword in generator functions

The combination of these features will make it possible to stream the HTML of a page in chunks generated by a single template representing the whole page. For example, it will be possible to do something like the following:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script async src="scripts/bundle.js"></script>
{{yield}}
</head>
<body>
<header>
<h1>Test</h1>
</header>
{{yield}}
{{contentPromise}}
{{yield}}
<script type="application/json">{{dataBundlePromise}}</script>
</body>
</html>

The above example uses multiple yields in order to stream the page in custom optimized chunks:

  1. head with an async script tag to kick off a parallel load and execution of the external scripts
  2. the top page chrome before any data is loaded
  3. the main HTML content for the page
  4. the data needed to bootstrap the page

@pypmannetjies pypmannetjies marked this pull request as draft November 19, 2020 15:51
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

Successfully merging this pull request may close these issues.

1 participant