Hi, I'm trying to improve the performance on one of my pages. In order to do so, I want to flush the top part of the page (site-wide header, and a few javascript references that are static for all users) as soon as my server receives the request. Then, after doing the more expensive DB operations that generate the rest of the page, I'll send those down as well.
To start off, I created a simple
test page, inserted an h1, then a <% response.flushBuffer %>, then a function call that triggers a breakpoint. I would expect the server to send everything up to the h1 down to the browser, and then not send the rest of the page until I resumed the breakpoint. In practice, though, nothing is sent until after I resume the breakpoint, and the whole page is sent down at once.
I read that this might be due to some sort of buffer size in
Tomcat or
JSP, so I inserted 20kb worth of padding data before the h1, but still I see the same behavior: nothing is sent, and then at the end of the page everything is sent. I also read that this might just be due to the browser not rendering data until it has "enough", but I fired up wireshark and sure enough nothing is being sent back at the HTTP level until after I resume the breakpoint and the whole page is rendered.
So how can I make flushing actually flush part of the response down to the client prematurely? (I'm using
Struts and JSP, with Tomcat as the webserver.)