MVC jquery $.get vs $.ajax browser cache

From past blogs you will see that I am in the process of being a rogue developer.  Off on my own converting a dinosaur of an app to the latest greatest…which when I started was MVC. Ok just a bit Microsoft biased. 

Not long ago I noticed that my jquery action calls seemed to be caching in the browser.  This was quite frustrating.  I have a list.  User goes into the detail makes an update and when coming back to the list the updates were not there.  We have all been there CACHING!!!  It can be a huge issue and hard to trouble shoot.  Sometimes you don’t even  notice it until it is too late.  Well there is a little catch here that I was just informed about from http://aaron.stemen.me/blog/.  We were working on a project that was caching. This is in IE only of course.  The rest of the browsers did not have an issue.  Working in corporate America, we do see a big influence on the default browser being IE.  Well this is a problem.  

The first trick I found addressed the caching issue in an unusual way, which will probably cause performance issues in the future.

I appended a date to the end of my action url overriding the default browser cache and fooled the browser to thinking it was not the same action URL you just served up so full action please. 

<%= Url.Action(“List”, “Something”) %>’ + ‘?’ + (+new Date());

 NOW I know the correct way to do this.   Can I have a refactor please:

 change my actual function call to:

$.ajax({url: url,
       cache: false,       success: function (data) {     });
      $(listView).hide(speed);
       $(listView).html(data);
       $(listView).show(speed);
       });

Most likely a horrible mass replace and a lot of missing }) to work through to fix.  Basically the .get allows the browser to determine when it should cache the results and the .ajax allows the developer to decide.

About dorothyjarry

Super Dots
This entry was posted in Coding/Development. Bookmark the permalink.

One Response to MVC jquery $.get vs $.ajax browser cache

  1. Chris Slee says:

    Great article. This actually helped me to figure out an issue I was having.

    Nice work.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s