Arun
Arun

Reputation: 1704

Avoid browsing cache in browsers

i want to avoid browsing cache while viewing a document. Please help me solve this issue by using java script or by any other method.

Regards,

Arun

Upvotes: 0

Views: 102

Answers (3)

Lee Kowalkowski
Lee Kowalkowski

Reputation: 11751

Since you asked "in JavaScript" I'll add that you need to use a different URL each time you view the document in JavaScript. E.g.

<a href="/a-document" onclick="this.href += '?' + new Date()">

(this is far from robust, it just illustrates the basic principle of the technique)

You'd only really do it this way if you were unable to control the server (e.g. if you aren't the owner).

Upvotes: 1

a&#39;r
a&#39;r

Reputation: 37029

Add the following header to your response:

Cache-Control: no-cache

Upvotes: 0

Jakub Konecki
Jakub Konecki

Reputation: 46008

Set content-expiration header in your response.

    var cache = HttpContext.Curent.Response.Cache;
    cache.SetExpires(DateTime.UtcNow.AddDays(-1));
    cache.SetValidUntilExpires(false);
    cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
    cache.SetCacheability(HttpCacheability.NoCache);
    cache.SetNoStore();

Upvotes: 3

Related Questions