tags:

views:

45

answers:

2

I have an application and in order to get the images to load into the app I had to use a proxy. So the urls for the images are not .jpg they are .php?var=value They seem to load much slower even after they have already loaded once, I don't really know how it works, but I am thinking that the proxied images are not being cached. Am I correct?

Thanks.

A: 

Your PHP-file might have declared a no-cache flag, or a low expiry time. Try opening both urls in a viewer which shows the full http headers.

Every proxy has its own settings how to deal with caching and different file types. A JPG is often seen as a static file, so it's safe to cache it. PHP files however are seen as dynamic scripts, who produce a different output every time. But this completely depends on your proxy's configuration.

Gerrit
Well the proxy accepts parameters for mime-type and headers, I have the mime-type set to "image/jpeg" but I don't know what to put for the headers so I didn't set them. Do you know what I should put for the headers? Thanks.
John Isaacks
Nevermind after studing the script it looks like it is just checking to see if the parameter headers == "true". So I guess I should set that?
John Isaacks
+2  A: 

IE (and maybe other browsers) doesn't cache URLs with any kind of ?query=string&foo=bar if there are no caching headers in the response. You have to explicitly set the Cache-Control and Expires headers for these to be cached.


In PHP, the way to set headers is this:

// can be cached by browser, and also by intermediate caches (i.e. by everybody)
header('Cache-Control: public');

// is fresh (doesn't have to be re-checked) until that date
header('Expires: Fri, 17 Apr 2009 23:50:00 GMT'); 

Caveat: you need to send headers before content, unless you use output buffering.

Piskvor
Can you please tell me or point me to a place that explains how to set that? Thanks.
John Isaacks