Link to home
Start Free TrialLog in
Avatar of Jagdeep Singh
Jagdeep Singh

asked on

Disable client side browser caching

Disable client-side caching in all browser. We are using Angualrjs.
For disabling the cache, I used HTML meta tags:-
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="EXPIRES" content="0">
    <meta http-equiv="PRAGMA" content="NO-CACHE">
but need a best solution
i.e.: http://www.i18nguy.com/markup/metatags.html
Avatar of leakim971
leakim971
Flag of Guadeloupe image

what is the issue ? do you want this for all browser or just Internet Explorer
Avatar of Dr. Klahn
Dr. Klahn

Thing is ... you can request this, but the browser is not required to honor the request.  Firefox, for one, makes its own decisions on what to cache and what not to cache.

As of last year, Pragma no-cache is the only thing that works with Edge, so you're probably stuck with using that.

https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/10739540/
The issue I had with IE was, as in AngularJS we request templates(to fill views) and data with ajax, we got the same content when we expect content different.
Is this your issue?
To do 100% browser cache busting will require a few additional headers to be sent.

Here's the header set I use in my PERL CGI scripts...

    push(@headers, "Expires: Mon, 01 Jan 1970 00:00:00 GMT\n");
    push(@headers, "Date: $now\n");
    push(@headers, "Last-modified: $now\n");
    push(@headers, "Pragma: no-cache\n");
    push(@headers, "Cache-control: private no-cache no-store must-revalidate max-age=0 pre-check=0 post-check=0\n");
    push(@headers, "Status: $code\n");
    push(@headers, "Content-Type: text/html\n");
    push(@headers, "Location: $new\n") if $new;
    push(@headers, "\n");

Open in new window


Just change the end from a Location: directive to your content payload.
I was just thinking about Dr. Klahn's comment + should mention... If you're cache busting + sending a redirect (3XX) do yourself a favor + send a 302, rather than 301.

If you send a 301, then this will cache in browsers forever, so if you make a mistake with your 301 target + change the target, no returning visitor will ever see your change...

So in addition to cache busting headers, be sure you send a 302, if you're doing a redirect.

Note: Cache busting is far more complex than it may appear to be at first glance.

Be sure to test your code with latest Chrome + Firefox after you've finished your coding, just ensure everything's working as you expect.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.