sEcho makes caching difficult - any ideas?

sEcho makes caching difficult - any ideas?

rasmusvhansenrasmusvhansen Posts: 4Questions: 0Answers: 0
edited September 2012 in General
I have a site where the datatables are redrawn every 5 seconds, thus calling the server.

However to save bandwidth and processing time, I have overriden the fnServerData function so it uses the isModified functionality of jquery.ajax (http://api.jquery.com/jQuery.ajax/)

This causes jquery to send the If-Not-Modified header which the server uses to send a 304 if nothing has been modified.
For components where I just use plain jquery ajax call this works fine.

The problem is that when datatables makes the call, it appends the sEcho=x to the url thus changing the url every time. When jQuery tries to look up the etag of the previous query it does not find anything as the url has changed (sEcho=2), and thus the server will send a 200 status code and the full dataset instead of a 304 and no data.

Is there any good workaround for this?

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    You could modify the DataTables code to not send sEcho - however, it is there to stop async redraw issues. For example if request 10 takes 8 seconds (for whatever reason), request 11 would already have gone out and might have been returned before the answer for 10 comes back - thus resulting in a horrible mixup and out of date data being displayed.

    If you don't think that will ever happen, then just remove sEcho - or use fnServerParams to delete it from the parameters being sent to the server.

    Allan
This discussion has been closed.