Check for newer version of stored page issue

While implementing a new feature on my job I encountered the a problem. From my angularJS controller I was making a call to a ASP.NET MVC controller function which looked like this:

var initialize = function() {
return $http({
url: "../someURL/",
method: "GET"
})
};

Everything went nice and I could see the content I expected. I changed a few parameters and went to another page. After some time I came back and saw that the content I edited was missing. I checked the database and saw that everything is fine there.

Sticking a breakpoint in the controller function made me realize that the function wasn’t called every time the page loads. As it turns out it was a problem with the settings of Internet Explorer.

One way to solve the problem is to enable “Check for newer version of stored page” in the settings but this isn’t an option here because I can’t know how each user configures his machine. Another way of doing this is with a little hack.

var initialize = function() {
var date, url;
date = new Date();
url = "../someURL/" + date.getTime();
return $http({
url: url,
method: "GET"
})
};

This way you will force IE to get the latest version of the web page because the date.getTime function will always return a different value and you will be visiting a different page.

Hope this helps you a bit.

Until next time, happy coding :)

Telerik reports – Missing operand before “=”

Book challenge – recap