Search code examples
javascriptajaxjakarta-eebrowser-cachehttp-caching

Force Cache Update for AJAX Requests


I am working on a large Java EE based enterprise portal. The users navigation is retrieved via jQuery-AJAX requests. Since the navigation is rather big and these AJAX requests to the server are a bit long running, I use

cache: true

option to let the browser store the request in its cache and later on retrieve results for repeating requests.

So far so good. In some cases, like e.g. navigation entries have changed or the user changed the frontend language, I need make the browser reload the requests freshly from the server.

I know, I can use "cache: false", but instead of just bypassing the browser cache, I'd rather make the browser update the obsolete cached responses by requesting fresh data from the server.

Is there any option I can add from frontend or backend side to the requests or their results, to make the browser discard the obsolete results with newly retrieved values?


Solution

  • I have encountered this same issue. I found that by setting the HTTP header "Last-Modified" on the HTTP responses, the browsers automatically refreshed the cached data based upon the age of the cache content.