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

Support template streaming #499

Closed
seanlinsley opened this issue Dec 9, 2017 · 3 comments
Closed

Support template streaming #499

seanlinsley opened this issue Dec 9, 2017 · 3 comments
Labels
request Request for new functionality

Comments

@seanlinsley
Copy link

seanlinsley commented Dec 9, 2017

Rocket already supports file streaming, but template streaming would also be a valuable tool for application developers.

Template streaming allows the server to stream HTML as it's generated, so that the browser is able to parse & render it earlier than it otherwise would.

The most likely slowdown for page rendering is expensive / poorly optimized database queries. This allows the browser to eagerly load assets and render page navigation elements while the server is finishing up the actual content of the page. This optimization is especially important for mobile users, because network latency can easily add 5 seconds to page render time (especially if the page requires JS).

Template streaming is supported by Rails, and Django users have found hacky solutions to get similar behavior.

It seems that there are two possible implementations:

  • update the template rendering libraries to return an iterator
  • have the application developer wrap certain parts of the HTML in a closure, communicating that the server can now pause to send all previous HTML to the browser
    • this is what Rails does, with closures passed to provide
@SergioBenitez SergioBenitez added the request Request for new functionality label Dec 14, 2017
@SergioBenitez
Copy link
Member

SergioBenitez commented Dec 14, 2017

I think this would be great! Thanks for bringing it to the forefront; I'll keep this in mind.

@sunng87
Copy link
Contributor

sunng87 commented Dec 15, 2017

Template streaming sounds like an interesting idea. I will do some experiment on handlebars-rust too.

@SergioBenitez
Copy link
Member

Moving to async (see #17) should be make this easy to implement, assuming support from templating engines. Because #17 covers the former, and because generally Rocket does not itself provide a templating engine, I'm closing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Request for new functionality
Projects
None yet
Development

No branches or pull requests

3 participants