Showing posts with label Internet Explorer. Show all posts
Showing posts with label Internet Explorer. Show all posts

Tuesday, April 21, 2015

Defining and using Server variables in the html head section of page

My browser was caching the javasscripts and css and it gets annoying when you are multiple design changes to code. So I decided to do cache busting. I defined a Random number variable in code behind and wanted to use it in html <head> so that every time a request is made, the browser takes it as a new request to the server with a fresh copy of styles and javascript files. The solution is a little quirky, but works:

     <link href="mystyle.css?rn=<%="" +Rand %>" type="text/css" rel="stylesheet"/>

where:
rn : is variable for Random Number
Rand : is server side generated Random number

Considering the Random number generated as 1234, the output would be like below:

     <link href="mystyle.css?rn=1234" type="text/css" rel="stylesheet"/>


Note: Use this for development only. Caching is always good to have in production to speed up loading times. With any new build of css/javascript, a version number can be assigned to get a fresh copy.

Wednesday, March 6, 2013

AJAX Caching issue in Internet Explorer (IE) 9 (way back upto IE 6)

I had been pulling my hair apart for resolving the browser compatibility issue. My MVC App has been working well in other browsers, but while doing testing, I found a notorious issue in IE. I had been hung on this issue for several hours. Tried clearing history/cache.. No luck. Tried using the cache trough developer tools (F12)... No luck.. Tried resetting the Browser to its default installation, thinking I might have accidently clicked on a setting for the browser to malfunction... No luck! restarted the machine a couple of times.... But I guess I was looking at the wrong place. Doing a google search for the correct keywords might have helped in the first place! Further research led me to find that IE caches the AJAX requests while others don't. Thats actually BAD news for me, because that gives me inconsistency in data.


Fellow internet geeks had posted a few solutions to overcome this issue:

http://dougwilsonsa.wordpress.com/2011/04/29/disabling-ie9-ajax-response-caching-asp-net-mvc-3-jquery/

http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/

http://ivida.co.uk/2011/09/29/ie-9-ajax-request-caching-mvc/




This worked for me! Yay!

$(document).ready(function() {
$.ajaxSetup({ cache: false });
});