Random Querystring to Avoid Ie Caching

Random Querystring to avoid IE caching

So, in the end, the only reliable way to do this (thanks to IE6) is using a
random,
or
time bound
querystring.

You could use a
time bound querystring
that only changes every 15 seconds (or any other amount of time), so you'd lower the server hit count, as you'd see locally cached content for those 15 seconds.

If you have
a
standard
compliant
browser, you can get away with only using
ETags.

How to disable cache in InternetExplorer 8

Go to Internet Options. On the General tab, under Browsing History click Settings. Select the "Every time I visit the webpage" radio button.

This doesn't "disable" the cache per se, but it should fix your underlying problem - the JS files should be reloaded every time.

How can you prevent Internet Explorer from caching HTML without using random query-strings

Have you tried the no-cache and expires meta-tags?

Other than that, random generated query-strings are the way to go. In my opinion, its not not that big of a deal. domain.com/stories/man-walks-on-moon/s34b is not exactly making my eyes bleed. And you will still achieve great indexing as far as search engines go.

Prevent IE11 caching GET call in Angular 2

Today, I also had this problem, (damn IE).
In my project, I use httpclient, that hasn't BaseRequestOptions.
We should use Http_Interceptor to resolve it!

import { HttpHandler,
HttpProgressEvent,
HttpInterceptor,
HttpSentEvent,
HttpHeaderResponse,
HttpUserEvent,
HttpRequest,
HttpResponse } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

export class CustomHttpInterceptorService implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler):
Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any>> {
const nextReq = req.clone({
headers: req.headers.set('Cache-Control', 'no-cache')
.set('Pragma', 'no-cache')
.set('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT')
.set('If-Modified-Since', '0')
});

return next.handle(nextReq);
}
}

Module provide

@NgModule({
...
providers: [
...
{ provide: HTTP_INTERCEPTORS, useClass: CustomHttpInterceptorService, multi: true }
]
})

Unexpected Caching of AJAX results in IE8

IE is notorious for its aggressive caching of Ajax responses. As you're using jQuery, you can set a global option:

$.ajaxSetup({
cache: false
});

which will cause jQuery to add a random value to the request query string, thereby preventing IE from caching the response.

Note that if you have other Ajax calls going on where you do want caching, this will disable it for those too. In that case, switch to using the $.ajax() method and enable that option explicitly for the necessary requests.

See http://docs.jquery.com/Ajax/jQuery.ajaxSetup for more info.

Internet Explorer and JQuery/AJAX $.get() not working

You're missing two semicolons, which IE will choke on. I've also formatted your code and made a few other tweaks:

function get_number() {
// Append a "random" number to the query string to prevent caching:
$.get("test5.php", { num: Math.random() }, function(response) {
// If you don't want to pass any data, you can omit the "data" parameter
var number = response.number;
$("#number_display").html(number);
}, "json"); // <---
}

$(document).ready(function() {
$('#get').click(function() {
get_number();
});
}); // <---

Edit: After your comment, you most likely have a caching issue--IE can be aggressive in caching GET requests. To get around this you could append a parameter to your request that will force IE to hit the server again.

Why is the page still caching even after the no-cache headers have been sent?

So long as your server ignores URL parameters, you can bypass any browser caching by fetching "url.csv?(random number)" instead of "url.csv".

Prevent browser caching of AJAX call result

I use new Date().getTime(), which will avoid collisions unless you have multiple requests happening within the same millisecond:

$.get('/getdata?_=' + new Date().getTime(), function(data) {
console.log(data);
});

Edit: This answer is several years old. It still works (hence I haven't deleted it), but there are better/cleaner ways of achieving this now. My preference is for this method, but this answer is also useful if you want to disable caching for every request during the lifetime of a page.

How to force a web browser NOT to cache images

Armin Ronacher has the correct idea. The problem is random strings can collide. I would use:

<img src="picture.jpg?1222259157.415" alt="Sample Image">

Where "1222259157.415" is the current time on the server.

Generate time by Javascript with performance.now() or by Python with time.time()



Related Topics



Leave a reply



Submit