bfcache causing issue with jQuery ajax request
I have a document that, when ready ($(function (){ ... })
), creates a request to load some data into a table. Users can then add items to this table. When items are added a request is sent to the server to save the item and then the row is added to the table client-side (very trivial application).
If a user adds a row and then navigates to a different page and then presses their back button, the request is made to re-load all the rows. However, bfcache takes over and serves that last request's result cached rather than a hit to the server! I had thought that a real new request would be made, but this isn't the case. Obviously, refreshing works as expected.
On the server side I'm using ASP.NET MVC 3, there is no caching on any of the action responses.
The obvious solution is to add cache: false
to the specific request or use $.ajaxSetup({ cache: false })
globally. This really isn't ideal because it should be the server controlling when requests should be cached.
Is there any easy way to disable the bfcache f开发者_JAVA技巧or ajax requests? Or is there an easy way to detect loading via bfcache so that I could cache: false
only if the page was loaded from back/forward?
精彩评论