Portal Home > Knowledgebase > Articles Database > [HTTP headers] Handling partially cached images


[HTTP headers] Handling partially cached images




Posted by zinga, 06-13-2010, 11:29 PM
A bit hard to explain in a few words, but here I go. It's a PHP script, but this issue probably has more to do with HTTP headers. If you're loading a large image by itself (ie, not embedded on a webpage - you're directly accessing the image's URL in your browser) and cancel the loading before the whole image loads, you can later come back to it and the browser will resume loading the image from where you stopped it. I'm trying to write a PHP script which sends images, but will also be able to handle this behaviour properly. The script supports caching and does send/check ETags and all. The issue is that, one would guess this resuming is done through sending Range HTTP requests, but my logging through Fiddler HTTP proxy isn't showing that the browser is doing this. Other possibility is that the browser just sends a normal request and it reloads the whole image, though I'm not getting that either. Here's an example request/response HTTP headers pair if I fully load the image without cancelling: However, if I cancel the image whilst it's loading, and then try to load it again later, this is the request/response pair I get: (if you want to test yourself, you can use the URL shown in the headers) And the browser fails to load the image, since the server isn't sending any back. The issue is that the browser thinks that it has a cached copy, but it doesn't (since the loading was cancelled) and, on the subsequent request, only checks whether its copy is okay through the If-None-Match header. The server script, sees the header, and sees that the ETag matches, so just assumes the client's cached copy is fine, so doesn't send anything back. EDIT: I'm using Firefox 3.6.3 BTW - might be different or same on others, but I do want this to work on Firefox regardless. Unfortunately, I'm having trouble trying to figure out how normal images load properly if partially cached, but this script isn't. From checking headers, the only difference between headers sent by the script and those sent by a normal static image is the Vary header (the script doesn't send these - I'm guessing mod_deflate is adding that line). Sending "Vary: *" doesn't seem to help however. Does anyone know the solution to this? Many thanks in advance!

Posted by MMrs, 06-15-2010, 08:35 AM
Did you try it without ETag?

Posted by zinga, 06-16-2010, 05:14 AM
Firstly, thanks for the response MMrs. I tried taking out the ETag header, but unfortunately, I still seem to get broken images if I try to resume a broken image load. This appears to be due to the fact that my script also checks the If-Modified-Since header that the browser sends: I'm sure taking out this check will make it *work*, but this will totally break "proper" caching support as well, which is something I don't really want. Thanks again.

Posted by zinga, 06-16-2010, 07:32 AM
Oh, as I can't seem to edit posts here, if you're wondering, the URL is the same (just appended nocache to stop the browser requesting the file from its cache) and the Vary header - that's just me testing stuff; it doesn't actually appear to have any effect.



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read