Reputation: 61
When my boss looks at our web projects, he always see the only web design. I will have to tell him to do CTRL + F5 for the new content to show.
Is there's a possible way of web coding to make an automatic CTRL + F5? Or in other words make clear cache when page load?
Tell me your thoughts. Thanks
Upvotes: 1
Views: 4440
Reputation: 3225
As SLaks suggested, you could use cache-busting URLs (eg with ?random={$rand} in the url). Alternatively, you could configure your dev site to send headers that tell all caches to expire the content almost immediately, so every fetch is direct without caching, eg something like this (if it's PHP):
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
Alternatively, get a boss who understands Ctrl+F5 - you think they'd have gotten used to that by now :D
Upvotes: 1
Reputation: 4325
To prevent the caching of HTML only, use a meta tag in the header specifying cache control, e.g.:
<meta http-equiv="Cache-Control" content="no-store"/>
This way your boss's browser will never cache the page. However, DO NOT enable this on production websites, as this will greatly increase the bandwidth used repeat visitors.
To prevent the caching of other resources on the server, you'll need to tweak the HTTP cache control headers it sends. Here's some documentation for Apache: http://www.askapache.com/htaccess/apache-speed-cache-control.html
If you want to always have up to date resources on production websites as well, the best solution is versioning, as outlined here: http://www.sitepoint.com/overcome-cache-conundrums/
Upvotes: 2