• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question to authors: AJAX caching

 
Ranch Hand
Posts: 250
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was playing with a very elementary AJAX example recently (user registration on a website) and I noticed that once a server-side asynchronous hit has been made for a particular "username" input-value, IE (I am not sure about other browsers) would not even make another HTTP Request for the same "username" input value next-time, it just returns the previous result. This led me to the belief that some amount of caching is involved here.

I am aware that the way out of this problem is probably the same as preventing browser-caching for any dynamic page (link for the un-inited), but I want to know where exactly does this caching happens, is it being done by the AJAX engine or is it similar to normal browser caching?

Thanks for your time and best wishes for the success of the book.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too thought that the browser-caching has some effects, but after setting the browser-caching effects like "expires, no cache etc.," I didnt had this problem.
I have a case where AJAX reads a dynamically generated xml file for every onChange event input. So far this is working fine in both IE and mozila.

I have another case where AJAX reads a static xml file on page load event.
If i change the xml file content, mozile shows it fine, but IE seems to read the old xml file for a while.
 
Author
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, at times browsers will cache the request and not make a new request even though we may want it to. This is controlled by the browser itself and not the XMLHttpRequest object.

You're on the right track for avoiding it. The techniques I'm aware of are setting the headers to "no cache" and "expires" and also to append a unique timestamp to the end of every URL that's used in an Ajax request, as the unique URL will force the browser to perform a fresh request each time.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am I right in thinking that another way to avoid this problem is to use POST rather than GET for sending your requests?

Since POST is designed to change the state on the server, the browser should send every request, even if the URL and data are exactly the same as a previous request.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am facing a similar problem. I want to refresh the data on my page every few seconds. But the AJAX script fetches the same data every time. I have used the random function in my servlet. The servlet shows a random number each time, but somehow the JSP calling the servlet through AJAX, is unable to do so.

It keeps on displaying the same data again and again.

I have tried using response.setHeader(" ..."), but that prevents any data from being displayed on the JSP. I am using IE.

Please suggest some solution.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use no cache headers or append a timestamp to the request. The timestamp will force IE to get new info.

Eric
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
on similar requirement I need to fetch tooltip only if it's changed from what it was displayed (cached) first time to avoid unnecessary server trip if content is not changed. any advise?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stick it in a JavaScript array, if the array element does not exist then go get it. I use that all the time in my applications.

Eric
 
Vicky Pandya
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks eric. however I don't know whether I got your idea correctly or I didn't clearly mention my requirement.

I do following
-grab and display tooltip(AJAX call) on mouse hover on a particular item.
-you are saying, i should store this tooltip value in JS array?
-but even if I store first time fetched value in array, how do I know whether value on server has changed or not for this tooltip (data for tooltip is being feed by another application, which can alter tooltip data on the fly while first app is running and displaying tooltip).

any ideas?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic