Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: How to enable browser caching of files like images? |
|
Author |
|
jack01
Joined: 28 Feb 2014 Posts: 27
|
Posted: Fri 23 Oct '15 16:53 Post subject: How to enable browser caching of files like images? |
|
|
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
|
Posted: Sat 24 Oct '15 9:51 Post subject: |
|
|
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
|
Posted: Mon 26 Oct '15 11:57 Post subject: |
|
|
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
|
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 27 Oct '15 0:28 Post subject: |
|
|
that is what Steffen already suggested and did not work |
|
Back to top |
|
|
|
|
|
|