async, on-demand lazy rendering for jinja2 possible?

est electronixtar at gmail.com
Tue Jul 22 04:00:28 CEST 2014


Hi all,

Been reading @igrigorik's posts https://www.igvita.com/archives/

I found that flush response as early as possible is crucial for a website
performance.

I wanna make Time To First Byte (TTTFB) happen as early as possible with a
Jinja2 site,

Suppose a typical Jinja2 template:

<html><head>
  <title>{{ site_title }}</title>
</head><body>
<ul>
{% for item in items %}
  <li>item</li>
{% endfor %}
</ul>
</body></html>

Let's presume site_title is static and known in view function from the
start, I wanna flush everything before <body> to the client as early as
possible, then items was a query from db, it's kinda slower, let's flush
the everything below  <body> later in a second TCP packet.

This looks like impossible at the moment. I searched the Jinja2 docs, the
closest thing I've found is the streaming template API

jinja2.Template('Hello {{ name }}!').stream(name='foo')

Which still requires all variables to be ready before rendering.

Is there a way to stream partial template results with partial template
variables? This would be great help making faster websites. Other template
engine than Jinja2 is welcome as long as it's in python! Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140722/b150ed15/attachment.html>


More information about the Python-list mailing list