Is it possible to send html HEAD early (chunked)?

Maxim Dounin mdounin at mdounin.ru
Mon Jul 14 12:54:10 UTC 2014


Hello!

On Sun, Jul 13, 2014 at 02:49:18PM +0200, Martin Grotzke wrote:

> Hi all,
> 
> inspired by the bigpipe pattern I'm wondering if it's possible to send the
> full html head so that the browser can start downloading CSS and javascript
> files.
> 
> An idea would be that the proxied backend uses a chunked encoding and sends
> the html head as first chunk. The body would be sent as a separate chunk as
> soon as all data is collected.
> 
> Not sure if this is relevant: In our particular case we're using ssi in the
> body to assemble the whole page, and some of the includes might take some
> time to be loaded. The html head contains an include as well, but this
> should always be loaded from the cache or should be served really fast by
> the backend.
> 
> What do you think about this? Has anybody tried this already?

By default, nginx just sends what's already available.  And for 
SSI, it uses chunked encoding.  That is, if a html head is 
immediately available in your case, it will be just sent to a 
client.

There is a caveat though: the above might not happen due to 
buffering in various places.  Notably, this includes 
postpone_output and gzip filter.  To ensure buffering will not 
happen you should either disable appropriate filters, or use 
flushes.  Latter is automatically done on each buffer sent when 
using "proxy_buffering off" ("fastcgi_buffering off" and so on).  
Flush can be also done explicitly via $r->flush() when when using 
the embedded perl module.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list