rwf2 / Rocket

A web framework for Rust.
https://rocket.rs
Other
24.4k stars 1.56k forks source link

Support template streaming #499

Closed seanlinsley closed 5 years ago

seanlinsley commented 6 years ago

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:

SergioBenitez commented 6 years ago

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

sunng87 commented 6 years ago

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

SergioBenitez commented 5 years ago

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.