views:

214

answers:

3

I have a web application on a site that takes a while (~10 seconds) to complete a portion of the page near the bottom - it has been as optimized as it can be, and caching is not an option.

We have compression enabled on the server via an .htaccess directive SetOutputFilter DEFLATE the problem is this causes the whole page to be held until completion before it starts outputting to the user, this is not optimal as the user sees nothing until the page completes.

I have also tried it via the php ob_start("ob_gzhandler"); method.

Currently I have a <FilesMatch > in my .htaccess restricting this specific script from being compressed.

Basically my question is this - Is there a way to say chunk gzip or deflate so that the user gets it in pieces, so they can see that the page has begun loading?

+1  A: 

I would say: no. I think there is now way provided by HTTP.

rami
+1  A: 

If you are using the ob_start("ob_gzhandler") method, you can do this - you need to look at the flush and ob_flush functions.

Some sample code - try loading with curl, or use fiddler to inspect the actual http responses

<?php
ob_start('ob_gzhandler');
print "chunk 1";
ob_flush();
flush();
sleep(2);
print "chunk 2";
ob_end_flush();

Unfortunately, browsers don't seem to display this in chunks - I think this is because the data of each chunk is too small. You can verify this effect by calling wget -O - -q http://chunktest/chunktest.php on your test file.

There are some more useful resources here

timmow
Alright, I found this promising, but after a little testing it doesn't appear to work.I added echo str_repeat(' ', 1000000); before the ob_flush for good measure to ensure when its flushed out to apache, apache would flush it out to the browser.I get the same results, browser, wget and curl
donatJ
A: 

If the page is that long of a load time, the creative way to handle it is to use a very quick loading page with an ajax call to that long-loading content on the page. We do this for the pages that pull detailed member usage statistics... Other sites, like Adsense for example, do this on their reports page.

Well I'd strongly like to avoid a dependence on JavaScript - an iFrame would probably be workable though.
donatJ