How to make the browser cache an image

T

Thomas Mlynarczyk

Hi,

There's a thread here dealing with the opposite problem, and I know I cannot
force any browser to do anything, but I'd like to know which is the most
promising way to tell a browser to cache an image.

Background: There is a number of images which are used on every single page
of a website (stuff like logo and background image) and I don't want the
browser to reload them every time from the server (or even "ask" if they're
still "fresh"). From what I've read so far, this seems to be a .htaccess
job, but what exactly must I put in there? Or are there other possibilities?

Thanks in advance,
Thomas
 
S

Steve Pugh

Thomas Mlynarczyk said:
There's a thread here dealing with the opposite problem, and I know I cannot
force any browser to do anything, but I'd like to know which is the most
promising way to tell a browser to cache an image.

They usually are cached, do you have any evidence that yours are not
being cached? What's the URL of a sample page?

As ever the best place to start reading on cache issues is
http://www.mnot.net/cache_docs/

Steve
 
T

Thomas Mlynarczyk

Also sprach Steve Pugh:
They usually are cached, do you have any evidence that yours are not
being cached? What's the URL of a sample page?

Still under development. I just wanted to know what I can do to maximize the
chance that my images will be cached and thus minimize loading time.
As ever the best place to start reading on cache issues is
http://www.mnot.net/cache_docs/

Ah, yes, this one is very instructive indeed. Thanks for the link. As far as
I've seen, in my current configuration, no "Expires" or "Cache-Control"
headers are sent. I assume setting them to appropriate values would help
considerably - or at least that is what the article above suggests. Right?

Thomas
 
R

rf

Thomas Mlynarczyk said:
Hi,

There's a thread here dealing with the opposite problem, and I know I cannot
force any browser to do anything, but I'd like to know which is the most
promising way to tell a browser to cache an image.

Background: There is a number of images which are used on every single page
of a website (stuff like logo and background image) and I don't want the
browser to reload them every time from the server (or even "ask" if they're
still "fresh"). From what I've read so far, this seems to be a .htaccess
job, but what exactly must I put in there? Or are there other
possibilities?

Why should you worry. The internet works just fine by itself(*). Don't try
to change it but rather spend your time on making your page content better
:)

(*) Many people have spent a *LOT* of time and money sorting out the caching
and refreshing algorithms. These people have a vested interest in the
matter, being the *large* bandwith providers - the people who own the
gigabit pipes from counry to country, and the *large* users of their
services, the top level suppliers of that bandwidth. Don't try to
second-guess them.

Bottom line: leave the cache alone.
 
S

Steve Pugh

Thomas Mlynarczyk said:
Also sprach Steve Pugh:


Still under development. I just wanted to know what I can do to maximize the
chance that my images will be cached and thus minimize loading time.

As rf says you almost certainly don't need to do anything as caching
tends to take care of itself under normal circumstances.
Ah, yes, this one is very instructive indeed. Thanks for the link. As far as
I've seen, in my current configuration, no "Expires" or "Cache-Control"
headers are sent. I assume setting them to appropriate values would help
considerably - or at least that is what the article above suggests. Right?

Are your images likely to change frequently? Are you images being
dynamically generated? If your images are static then you really don't
need to provide any additional information. The most important thing
to check is that your server is sending an accurate last modifed date
in the headers for the image (and it almost certainly is). If it's
doing that then the cache system will work just fine.

Steve
 
R

rf

Steve said:
Are your images likely to change frequently? Are you images being
dynamically generated? If your images are static then you really don't
need to provide any additional information. The most important thing
to check is that your server is sending an accurate last modifed date
in the headers for the image (and it almost certainly is).

It *most* certainly is if said server is owned by a hosting company. They
also have a vested interest, they do *not* want to waste bandwith when they
can rely on the caches out there to serve the content without a hit on their
servers.
 
T

Thomas Mlynarczyk

Also sprach Steve Pugh:
Are your images likely to change frequently?

No. They are design elements used on every page.
Are you images being dynamically generated?
No.

If your images are static then you really don't
need to provide any additional information. The most important thing
to check is that your server is sending an accurate last modifed date
in the headers for the image (and it almost certainly is). If it's
doing that then the cache system will work just fine.

With Mozilla I can have a look at the header info for HTML files - but how
can I see those for images?
 
T

Thomas Mlynarczyk

Also sprach rf:

[Caching of images to minimize loading time]
Why should you worry. The internet works just fine by itself(*).
Don't try to change it but rather spend your time on making your page
content better :)
Bottom line: leave the cache alone.

Hm. Having tested my pages online by now (using ADSL), I must admit that my
browsers indeed seem to handle the caching properly. Even better than I had
thought. Mozilla does not even show a flicker - wow! Still, with a 56K
modem, the initial loading may take a few seconds (7 pictures, about 12KB
together - plus one stylesheet of about 5KB [I guess it can be optimized a
bit more] plus the actual HTML document).

So I guess I better follow your advice and cancel that cache thing from my
chores list.

Thanks to all of you!

Thomas
 
R

rf

Thomas Mlynarczyk said:
Also sprach Steve Pugh:


No. They are design elements used on every page.


With Mozilla I can have a look at the header info for HTML files - but how
can I see those for images?

Point the browser at the image?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top