views:

34

answers:

1

Hi,

I need to load almost 100's of images in a single page on my website. ( product image, lots of them ). Whenever image change for product, url for that image also changes. i.e. for one url corresponding iamge never changes. Now I want to make sure that for a same person browsing through website, the image must not load again.

Is expire header is good enough ? ( sometime the browser still try to load it when refreshed manually )

on server side my python script always return 304 when if modified since header available without checking its value as each image has unique url. It normally works good but sometime when images are partially loaded and user move to another page, user see half downloaded images next time he land on the same page as server return 304. so how reliable if modified since header is ? and what are other alternative ?

Thanks.

edit 2:

what should be the content length for 304 response ? should it be the original content or actual content ( i.e. 0 ) ??

A: 

When you reload manually, most browsers disregard the caching headers, so this is normal and expected behavior.

The Expire header should be sufficient for this purpose.

As for the partial load, it can happen that the TCP connection gets broken while the image is loading; if you didn't specify Content-Length when sending the image, some browsers may assume that the connection was closed because all the data were sent. If Content-Length (a.k.a. image size in bytes) is specified, the browser should note when it doesn't have the complete image and will re-download it unconditionally the next time.

When sending the 304 Not Modified, it's not necessary to send Content-Length.

Piskvor
what should be the content length for 304 response ? should it be the original content or actual content ( i.e. 0 ) ??
iamgopal
@iamgopal: The 304 doesn't need to send Content-Length.
Piskvor
Hmmm, any reason for the downvote? As far as I know, the answer is factually correct...
Piskvor
i didn't downvoted you, and thanks for the answer.
iamgopal
@iamgopal: You're welcome. (I don't suspect you :))
Piskvor