Solved

Expiration date on Image files?

Posted on 2004-03-26
37
1,158 Views
Last Modified: 2012-08-13
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
     http://www.experts-exchange.com
for instance,
      http://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
0
Comment
Question by:DanRollins
  • 14
  • 12
  • 11
37 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 10692284
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.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10692295
in filter you need:
response.setDateHeader ( "Expires ", datemillisecond );
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10692568
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
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10692580
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?
0
 
LVL 92

Expert Comment

by:objects
ID: 10692891
> 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.
0
 
LVL 92

Expert Comment

by:objects
ID: 10694047
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10694171
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
0
 
LVL 92

Expert Comment

by:objects
ID: 10694182
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.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10694215
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
0
 
LVL 92

Expert Comment

by:objects
ID: 10694224
It's a tradeoff between speed and disk space. As you cache more files, and for longer periods the disk space requirements increase.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10694242
What I'm trying to do is avoid network traffic.
0
 
LVL 92

Expert Comment

by:objects
ID: 10694265
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.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10696436
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 10696493
It depends on the clients cache settings.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10696710
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 10697633
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.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10698073
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
0
 
LVL 92

Expert Comment

by:objects
ID: 10699897
> 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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 49

Author Comment

by:DanRollins
ID: 10700900
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 10700924
> 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.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10701054
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
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10701424
>>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)
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10701427
let me know if you need futher help on ServletFilter.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10701543
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
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10705005
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
0
 
LVL 92

Expert Comment

by:objects
ID: 10707962
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.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10708135
>> 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
 
0
 
LVL 92

Expert Comment

by:objects
ID: 10708674
i was aware of that, the context of your comment just wasn't clear.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10710615
sorry object, I'm here to share, just don't have time to argue on pointless comments.
0
 
LVL 92

Expert Comment

by:objects
ID: 10710644
What argument??? I asked for a simple clarification of your comment.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10710684
and the clarification was given, what else do you want?
0
 
LVL 92

Expert Comment

by:objects
ID: 10710746
> what else do you want?

nothing, and I didn't ask u for anything so am not sure what u r carrying on about.
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10711628
Please stop this thread-polluting nonesense.  Thanks.
-- Dan
0
 
LVL 92

Expert Comment

by:objects
ID: 10711691
Sorry about that Dan.
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 500 total points
ID: 10717463
Sorry Dan, come back to the topic. I found that apache mod_expires does exactly what you are looking for. below will set expire one month later for all image files.

<Files ~ "\.(gif|jpe?g|png)$">
    ExpiresActive On
    ExpiresDefault "access plus 1 month"
</Files>

you can control in file, directory and/or location level. for more information:
http://httpd.apache.org/docs/mod/mod_expires.html
0
 
LVL 49

Author Comment

by:DanRollins
ID: 10750629
Though I am personally unable to test this, that looks like the ticket.  Thanks!
-- Dan
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10752574
you are welcome and thank for the A grade.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now