0

I'm working on a website, where the audience isn't very comfortable with computers. A complaint received often in the past was about (minor) new updates, though important ones not being visible (like date and times being changed). Problem: browser caching and people not knowing how to refresh a browser. Because of the rather large audience, it will be impossible explaining that to all of them.

We'll be putting an entire new site online very soon, so I suspect that this change will cause the browser to get the update...am I right on this one?

But in order to prevent the complaints of the past I would like a better control of the user's browser caching.

It would be best to put a caching time (between a day and one or two weeks) per page, because for the general info caching is a good thing, because it isn't updated that often and it isn't as sensitive to time as our calender is! But I want a new version of the calender within a day from the last visit. --> I would even consider caching parts of pages if possible (header and footer are less likely to change then content etc.)

What's the best approach? Should I change something on the server settings (as far as the hosting allows me to) and how can I do this (hosting control panel, php.ini)?

Or should I do something in PHP? Or in the HTML like I found over here: HTML Cache control

Or maybe a combination of some/all of the above?

Community
  • 1
  • 1
cowgirl
  • 51
  • 3
  • Html solutions do work (it depends on browser). I do not know about server-side no-cache system but maybe they can help. (But nothing is perfect) – Marco Mura Dec 09 '14 at 16:53

2 Answers2

3

You can either do this with PHP or HTML

PHP

<?php

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

HTML

<meta http-equiv="expires" content="Day, 01 Mon 2014 00:00:00 GMT"/>
<meta http-equiv="pragma" content="no-cache" />

make sure to put that in your main include file for php or html to do this for all pages. I would use the php header over html.

unixmiah
  • 3,081
  • 1
  • 12
  • 26
  • All pages should be allowed to be cached. Calender only for a period of 1 day, price table a week and some general info pages 2 weeks other for a month. Is this distinction and duration time possible using PHP and/or HTML? – cowgirl Dec 09 '14 at 17:31
  • you can use header("Expires: Sat, dd Jul yyyy 05:00:00 GMT") in php or in html. adjust the time for expired date/time and put it on the pages that needs it – unixmiah Dec 09 '14 at 17:56
0

You can achieve this by .htaccess:

<filesMatch "\.(php|html|htm|js|css)$">
  FileETag None
  <ifModule mod_headers.c>
     Header unset ETag
     Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
     Header set Pragma "no-cache"
     Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
  </ifModule>
</filesMatch>

This will expire the server cache and each request will get the new pages

saqibahmad
  • 962
  • 1
  • 9
  • 18
  • All pages should be allowed to be cached. Calender only for a period of 1 day, price table a week and some general info pages 2 weeks other for a month. Is this distinction and duration time possible using .htaccess? – cowgirl Dec 09 '14 at 17:30
  • As far as I can understand your code, you filter upon extension, but I don't do extensions, since I use routing creating nice SEO friendly urls... – cowgirl Dec 09 '14 at 17:46