Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74966
| From | est <electronixtar@gmail.com> |
|---|---|
| Date | 2014-07-22 10:00 +0800 |
| Subject | async, on-demand lazy rendering for jinja2 possible? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12160.1405994458.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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!
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
async, on-demand lazy rendering for jinja2 possible? est <electronixtar@gmail.com> - 2014-07-22 10:00 +0800
csiph-web