JTC
JTC

Reputation: 139

Cache Control headers not doing the JOB

I have tried all the headers i can find in the internet for my webpage not to store the cache, but it doesn't work. I have tried all the php headers, and the HTML meta tags you can ever find.

My webpage only runs smoothly when the " Disable Cache" is ticked under the network tab.

When i look at the cache storage under dev tools there is no data. So i think the headers are actually working, but the data updates when i manually clear the cache in the browser or when disable cache is ticked.

I dont think i have to do anything on the server side as when clear cache is pressed on the browser, everything runs fine.

NOTE: I have tried all solutions from stack overflow.

This is the last one i tried

<?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");
?>

Upvotes: 1

Views: 3807

Answers (1)

Ryan The Ghost
Ryan The Ghost

Reputation: 177

What is Cache?

Cache-Control is an HTTP cache header, Which simply Makes your website Faster, Also it can help your website when using Private Info!!!

How to see if my website is caching?

Inspect Elements -> Network -> click on the image / file -> Responses Header -> cache-control

Settings Up cache

For Php

<?php
header('Cache-Control: max-age=86400');
?>

For Apache

<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Cache-Control "max-age=84600, public"
</filesMatch>

For nginx

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 2d;
    add_header Cache-Control "public, no-transform";
}

I dont Want Cache

In that case you need to use :

<?php
header('Cache-Control: no-cache,no-store,must-revalidate');
header('Pragma: no-cache')
?>

If you dont see This taking effect, first try using it on another browser or removing your cache

Using Meta Tags

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

Checking if my Website is cached

#1 - Is cached A cached Website #2 - Is not cached A none-cached website

Upvotes: 1

Related Questions