Link to home
Start Free TrialLog in
Avatar of DanRollins
DanRollinsFlag for United States of America

asked on

Expiration date on Image files?

I don't know anything about JSP or Apache.  But you folks do!  So...

If you go to this page:
     http://www.google.com/
and then look at the IE6 cache files, you will see that the "Expiration Date" for the file named
      http://www.google.com/images/logo.gif
is set some time in the year 2038

But if you look at the cached GIF files that come in from this page
     https://www.experts-exchange.com
for instance,
      https://www.experts-exchange.com/images/logoBottom.gif
there is no expiration date.  

1) Why is that?
2) How can a site that uses JSP serve up a GIF file and specify an expiration date for it?

-- Dan
Avatar of kennethxu
kennethxu

this is not something that jsp do, instead, you can use Filter to set a expiration header for gif files.
let me know if you need further information.
in filter you need:
response.setDateHeader ( "Expires ", datemillisecond );
Avatar of DanRollins

ASKER

Thanks!

Is that something that an Apache-savvy website admin would know how to do if I email that info to him?

...and...

Can he set the server to send that header on some GIFs but not others?

-- Dan
No, You need to develop a ServletFilter for your webapp. Apache is a web server, not jsp server (formally, called servlet container). do you know what jsp server are you using?
> 2) How can a site that uses JSP serve up a GIF file and specify an expiration date for it?

Use a servlet to serve up your image.
I'm sorry, I'm a total idiot about these things... I'm just exploring a kookie idea I had that setting an Expiration Date to the distant future on seldom-changed image files might allow IE's cache to work more efficiently.

Has anyone ever checked into that?

-- Dan
Depends on your definition of more efficiently. If you take it to the extreme you could have a cache that stored everything it found, and never deleted anything, but the disk space requirements would increase until the disk was full.
By efficiently I mean "so that the client (IE6) does not request the file from the server or even bother to make a round-trip to ask the server if it has changed."

-- Dan
It's a tradeoff between speed and disk space. As you cache more files, and for longer periods the disk space requirements increase.
What I'm trying to do is avoid network traffic.
From a client perspective or server?

If from a client perspective then adjust the settings in your cache so it hangs onto files for longer for example by increasing its size, and purging it less often.
Yes, but also from the host perspective.   I want to ensure that the client uses a cached image rather than asking the host to resend it or even asking the host if it needs to be resent.  

For porposes of this discussion, assume that the cache on the client has plenty of space available.
It depends on the clients cache settings.
For purposes of this discussion, assume that the user's cache settings are set at the default, which is I believe,  

    Check for newer versions of stored pages:  Automatically

Which means:
   ...Over time if IE determines that the images on the page are changing
    infrequently it will check for newer images even less freqyently...

which to me, indicates that it *will* continue checking, at least sometimes.  And each "check" requires a roundtrip to the server.   Obviously, tiny GIF files for spacing or the corners of boxes, or button images -- never change.  So my theory is that if the SERVER sends an explicit caching instruction, that some network traffic could be avoided.
If you could (and I'm not sure you can), how would it handle if the resource *did* change at some point for whatever reason. If the browser never checked the server, then it would never download the updated resource.
That would be my question to you... :)

But in that rare situation, where the site was completely redone,.... say once per century, I'd imagine that there would be a way to handle it... for instance, use different filenames for the new corner GIF files.   THery may be another cache-control mechanism at the page-level that would force a flush of the embedded file references.

-- Dan
> That would be my question to you... :)

It was a rhetorical q really:) If if clients supported the approach u suggest it would leave no way for a client to know to grab new resource.

> THery may be another cache-control mechanism at the page-level that would force a flush of the embedded file references

A little inconvenient.

> THery may be another cache-control mechanism at the page-level that would force a flush of the embedded file references

This would require the client to have this mechanism implemented which it doesn't.
But the real reason is:  Google.com does it (set an "Expires" date far in the future) on their logo image file.   In general, the folks at google are not idiots, so there must be a mechanism or they (smart people that they are) must think that it's not too critical of an issue.
> Google.com does it

I think you'll find there is still some contact between client and server.

If you just want to set Expires then use a servlet or ServletFIlter to set it appropriately.
Indeed, the ServletFilter sounds like the way to go (though it seems like it should be easier... like a generic server setting).  I wish I had some way to know for sure if it would make any difference to site load times.

Thanks for all of your help so far.  I'll leave tis open for a few days.

-- Dan
>>I'm just exploring a kookie idea I had that setting an Expiration Date to the distant future on seldom-changed image files might allow IE's cache to work more efficiently.

just for you info, ie only check if an image is change once in one browser session. it doesn't always. so the expire thing ONLY HELP on one conditional get request to server in one browser process life cycle. (unless user clear cache manually)
let me know if you need futher help on ServletFilter.
Thanks kennethxu.
Can you identify an official Microsoft source that says that?  The only thing I found says that "it checks less frequently."

Assuming that it is true, my idea would only save the user a small amount of time... unless he closes the Browser (and thus ends the session).   There are enough EE user's complaining about too-long load-times that it may be possible that they are setting their caching options incorrectly, or are opening a new browser window with each EE email notification ...or something like that.

What's more, if 100,000 people log in 10 times per day, then that's 1,000,000 more times the server must needlessly handle a round trip for small GIF files that never change.  So it is still worth looking into, I think.

-- Dan
Hi Dan,

I'm sorry that I don't know if there is a MS doc state this. I doubt there is one. What I said is based on our experience with IE5.5/6. We check the server access log to observe the IE behavior.

Another thing that we have observed and might interest you is that IE will display the page before the images are downloaded. So if your page takes long time to load, it might not related to image. BTW, IE does need all css and js files for render the page.

I agree with you that a large amount small gif file worth looking into. I asked our apache expert about your Q. He said, you might want to look into mod_header. that will be more on configuration side comparing to Servlet Filter.

http://httpd.apache.org/docs/mod/mod_headers.html

Ken
WOuldn't the bevaviour depend on what the browser cache setting are?

> that IE will display the page before the images are downloaded

Thats right images are downloaded asynchonously.
>> WOuldn't the bevaviour depend on what the browser cache setting are?

Comment from DanRollins
Date: 03/27/2004 04:49PM PST
 Author Comment  


For purposes of this discussion, assume that the user's cache settings are set at the default, which is I believe,  

    Check for newer versions of stored pages:  Automatically
 
i was aware of that, the context of your comment just wasn't clear.
sorry object, I'm here to share, just don't have time to argue on pointless comments.
What argument??? I asked for a simple clarification of your comment.
and the clarification was given, what else do you want?
> what else do you want?

nothing, and I didn't ask u for anything so am not sure what u r carrying on about.
Please stop this thread-polluting nonesense.  Thanks.
-- Dan
Sorry about that Dan.
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Though I am personally unable to test this, that looks like the ticket.  Thanks!
-- Dan
you are welcome and thank for the A grade.