logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: How to enable browser caching of files like images?
Author
jack01



Joined: 28 Feb 2014
Posts: 27

PostPosted: Fri 23 Oct '15 16:53    Post subject: How to enable browser caching of files like images? Reply with quote

Hi,
using Apache httpd 2.4.17 on Windows 2008 R2. I have read several articles on web about image caching in browser, but can't really decide which method is suggested one. I have several static images on my web server that never change.

What is the method you are using to cache images (png, jpg, gif) at end-user browser cache? I would like to set this caching in the way when end-user closes its browser and starts it again, visit my web site and images are still cached.

Can you point me to some good tutorial how to set browser caching and also how to verify in browser (I prefer using Firefox if possible) that caching is really working and if possible how to monitor performance of caching vs. no-caching, to see the benefit of caching settings.
Regards
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Sat 24 Oct '15 9:51    Post subject: Reply with quote

You can place in you httpd.conf:

Code:
<FilesMatch \.(?i:gif|jpg|png|ico)$>
Header append Cache-Control max-age=2592000
</FilesMatch>


max-age=2592000 = 30 days
Back to top
jack01



Joined: 28 Feb 2014
Posts: 27

PostPosted: Mon 26 Oct '15 11:57    Post subject: Reply with quote

Steffen,
I did the following test:
1. Added above your settings in httpd.conf file and restarted Apache httpd.
2. Opened Firerfox 41 and pressed CTRL+SHIFT+DEL and deleted all of the settings in Clear All History dialog including cache (to have clean environment for testing).
3. Pressed CTRL+SHIFT+Q to get Web Developer Network browser window.
4. Typed in URL address and I see "HTTP 200 GET image.png" response. So image was loaded from server. From "Response headers" for one particular image I checked I see setting Cache-Control: "max-age=2592000". In Apache httpd response log I can also see the request was made from my computer IP address.
5. Browsing around to get to the same web page and image is not listed in "Web Developer Network", so browser did not request an image. Also no request in Apache httpd request log. But image is clearly displayed in browser, so this indicates browser is caching. So far no problem, works as expected.
6. Close down a browser and reopen and type in URL address and see again exactly the same as in step 4: No browser images caching! It looks to me that images are cached only during the browser session and if browser is closed down and started again browser image caching is lost.

What I have found out now is that web developer hard coded the following in HTML document:
Code:
<html><head><meta http-equiv="expires" content="0"></head>

and according to the http://cristian.sulea.net/blog/disable-browser-caching-with-meta-html-tags/ it looks like web developer has killed the caching in html document that is overriding my http header settings at httpd sever. So what ever settings I made it is just useless because of override. Am I right about this?
Thanks for help.
Back to top
PipoDeClown



Joined: 20 Dec 2005
Posts: 77

PostPosted: Mon 26 Oct '15 21:53    Post subject: Reply with quote

you can do a lot with headers at server level
http://httpd.apache.org/docs/2.4/mod/mod_headers.html#header
http://httpd.apache.org/docs/2.4/mod/mod_expires.html#expiresbytype

server can override headers sent by app
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7371
Location: Germany, Next to Hamburg

PostPosted: Tue 27 Oct '15 0:28    Post subject: Reply with quote

PipoDeClown wrote:
you can do a lot with headers at server level
http://httpd.apache.org/docs/2.4/mod/mod_headers.html#header
http://httpd.apache.org/docs/2.4/mod/mod_expires.html#expiresbytype

server can override headers sent by app


that is what Steffen already suggested and did not work Wink
Back to top


Reply to topic   Topic: How to enable browser caching of files like images? View previous topic :: View next topic
Post new topic   Forum Index -> Apache