How to avoid browser caching anything from a specific page

1.6k Views Asked by At

I have a slideshow that I preview (custom html/js) and to make sure that I get the most recent version from the DB every time I start the slideshow preview, I have these cache statements in my html file

<!DOCTYPE html>

<!-- preview:[true]-->

<HEAD>
<title>screen</title>

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />

However sometimes I still need to empty out the browser cache in order to get the most recent updates.

Is there anything else I can put in the head of my html file to prevent browsers from caching this for me? Chrome is what I mainly use, and where I have sometimes experienced this effect, but I would like a generic answer for all browsers.

---------------- UPDATE ------------------- So I included some cache control headers (thanks arkascha) but am still a bit suspicious =)

Here is what I added to my response (php/sym2)

    $response->expire();

    $now = new \DateTime("now");
    $response->setCache(array(
        'last_modified' => $now,
        'max_age'       => 0,
        's_maxage'      => 0,
        'private'        => true,
    ));

And that gives me the following Response headers

Cache-Control:max-age=0, private, s-maxage=0
Connection:Keep-Alive
Content-Type:text/html; charset=UTF-8
Date:Wed, 31 May 2017 08:41:19 GMT
Keep-Alive:timeout=5, max=100
Last-Modified:Wed, 31 May 2017 08:41:20 GMT
Server:Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8zh DAV/2 PHP/5.5.3
Transfer-Encoding:chunked
X-Powered-By:PHP/5.5.3

... and Request Headers displays as:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch, br
Accept-Language:sv-SE,sv;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Cookie:main=1111111; PHPSESSID=70c2e1a6f81a9d3dad59ed908f25b585
Host:localhost
If-Modified-Since:Wed, 31 May 2017 08:40:18 GMT
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36

But on my network tab (chrome) I still see a lot of "from memory cache" and "from disk cache" in the "size" column for different resources (what is the difference between those two by the way?).

Does the http header only affect the current page and not the associated resources such as .json files?

0

There are 0 best solutions below