Forum
04:58
10/08/2009
Hi, Tony!
Every GET request send to server has URL with unique nd parameter:
GET /baseUrl?_search=false&nd=1250155065874&rows=20&page=1&sidx=&sord=asc
Where the value of nd parameter is new Date().getTime()(see code of populate function in grid.base.js). It switches off all caching.
Moreover, changing prmNames from default value
{page:“page”,rows:“rows”, sort: “sidx”,order: “sord”, search:“_search”, nd:“nd”}
to, for example,
{page:“page”,rows:“rows”, sort: “sidx”,order: “sord”, search:“_search”}
don’t solve the problem. The function $.extend used in $.fn.jqGrid combines current properties of prmNames with default one and we have the same problem as before.
Setting prmNames to null follows to exception in the code of populate function in grid.base.js, because the code
…
prm[ts.p.prmNames.search] = ts.p.search; prm[ts.p.prmNames.nd] = new Date().getTime();
…
don’t test ts.p.prmNames or any it’s property (ts.p.prmNames.nd etc.) to null.
I don’t find any solution without changes in grid.base.js.
Best regards
Oleg
05:21
Moderators
30/10/2007
Hello,
Use beforeRequest event to remove this parameter. The event fires just before the request and when all parameters are set.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
05:41
10/08/2009
Hello Tony,
thank you very much for the advice. With
beforeRequest: function() {if (this.postData.nd !== undefined) delete this.postData.nd;}
the problem was solved.
Nevertheless, it would be probably better to change default value of prmNames from
{page:“page”,rows:“rows”, sort: “sidx”,order: “sord”, search:“_search”, nd:“nd”}
to {page:“page”,rows:“rows”, sort: “sidx”,order: “sord”, search:“_search” }. Then default jqGrid server data can be cached. If somebody has advantage from additional nd parameter, he can use it.
Best regards
Oleg
09:52
10/08/2009
Hello Tony!
Now it seems to me I understand at the end the meaning of nd parameter in URL of GET requests. I found out, that IE8 use incorrect caching on ajax GET-requests. It sends no request to server, but gets the old data direct from the cache. If one loads the same data directly in IE8-GUI, it works without any problems. This problem is known und discussed in Internet. I found no other solution as switching off the caching for IE8. It can be done for example with respect of nd parameter
beforeRequest: function() {
if ((!jQuery.browser.msie || (jQuery.browser.version !== “8.0″))
&& (typeof this.postData.nd !== 'undefined'))
delete this.postData.nd;
}
Here I delete nd parameter from the send data for all browsers instead of Internet Explorer 8.0.
By the way, jquery.ajax function has an additional boolean parameter cache. Setting of cache to false follows to adding “_” parameter to the URL of GET-requests with the same way and meaning as nd parameter. In the code of ajax function from jquery-1.3.2.js one can find following fragment
if ( s.cache === false && type == “GET” ) {
var ts = now();
// try replacing _= if it is there
var ret = s.url.replace(/(\\?|&)_=.*?(&|$)/, “$1_=” + ts + “$2″);
// if nothing was replaced, add timestamp to the end
s.url = ret + ((ret == s.url) ? (s.url.match(/\\?/) ? “&” : “?”)
+ “_=” + ts : “”);
}
where
function now(){
return +new Date;
}
In my opinion the option named cache: false will be imediately correct understanded. For undestanding of nd paramerer on the other side, one sould undestend directly the implementation of switching the caching off.
Switching of the cache only for IE8 seems to me the best way as a default behavior.
Best regards
Oleg
15:47
10/08/2009
Hello Mark
Thank you very much for your advice. I misunderstood meaning of some caching properties in HTTP header before. After you advice I read HTTP 1.1 RFC (14.9 from RFC 26156, http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3). I use now in my server response “Cache-Control: max-age=0“ in the HTTP header together with setting ETag. And now everything works how I want: local browser cache will be used, but every new request contains “If-None-Match“ header with the value of ETag received with the first request. If the data are changed server send new data, but if the data stay unchanged, it reply with short response “HTTP/1.1 304 Not Modified” without any data and Browser get data from its local cache. Exactly what I want.
Now the setting of Internet Explorer: “Check for newer versions of stored pages” (found in Internet Options > General > Browser history > Settings) with standard “Automatically” setting works for my URLs exactly as the setting “Every time I visit the webpage”. I am happy!
Of cause, I stay have to use
beforeRequest: function() {
if (typeof this.postData.nd !== “undefined”)
delete this.postData.nd;
}
because usage an unique nd parameter added to every GET-request switch cache off.
So my suggestion to remove nd parameter from the list of default parameters of prmNames properties stays actually.
Tanks a lot
Oleg
06:54
Moderators
30/10/2007
Hello,
Thanks for these coments and usefull information. I will think for this, but adding more and more parameters to the grid will make them not usefull. Also the genaral solution for me is
..jqGrid({
...
ajaxoptions : { here ajax options}
...
})
Also this will bring you to do what you want with the ajax calls.
Will investigate the second solution more deeper instead of first.
What is your opinion on this?
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
16:40
10/08/2009
Hello Tony!
At the end of the discussion I know what should be done on the server side for correct caching of GET results on the client side. No additional ajax option are required, at least to solve the problem.
The only problem what I see is using in jqGrid parameters in the form of objects like
jqGrid({
…
prmNames: {page:”page”,rows:”rows”, sort: “sidx”,order: “sord”, search:”_search”, nd:”nd”},…
})
Currently it is not possible to define shorter number of properties of prmNames. For successful caching I needs remove nd, for example. Creating a jqGrid with prmNames like
{page:“page”,rows:“rows”, sort: “sidx”,order: “sord”, search:“_search”}
gives nor results, because it will be expanded to {page:”page”,rows:”rows”, sort: “sidx”,order: “sord”, search:”_search”, nd:”nd”} by p = $.extend(…) at the beginning of $.fn.jqGrid.
Usage
beforeRequest: function() {if (this.postData.nd !== undefined) delete this.postData.nd;}
works, but is not nice.
So it seems to me the easiest way to allow remove some default values from prmNames would be to allow null values in prmNames.
If one change the code in “populate” function from
…
var prm = {}, dt, dstr;
prm[ts.p.prmNames.search] = ts.p.search; prm[ts.p.prmNames.nd] = new Date().getTime();
prm[ts.p.prmNames.rows]= ts.p.rowNum; prm[ts.p.prmNames.page]= ts.p.page;
prm[ts.p.prmNames.sort]= ts.p.sortname; prm[ts.p.prmNames.order]= ts.p.sortorder;
…
to something like
…
var prm = {}, dt, dstr;
if (ts.p.prmNames.search !== null) prm[ts.p.prmNames.search] = ts.p.search;
if (ts.p.prmNames.nd !== null) prm[ts.p.prmNames.nd] =new Date().getTime();
if (ts.p.prmNames.rows !== null) prm[ts.p.prmNames.rows]= ts.p.rowNum;
if (ts.p.prmNames.page !== null) prm[ts.p.prmNames.page]= ts.p.page;
if (ts.p.prmNames.sort !== null) prm[ts.p.prmNames.sort]= ts.p.sortname;
if (ts.p.prmNames.sort !== null) prm[ts.p.prmNames.order]= ts.p.sortorder;
…
than usage of
prmNames: {page:”page”, rows:”rows”, sort: “sidx”, order: “sord”, search:”_search”, nd:null}
will solve all my problems without callback function beforeRequest.
If a table has all non-sortable columns one could use
prmNames: {page:”page”, rows:”rows”, sort: null, order: null, search:”_search”, nd:null}
If the table need no data paging, then
prmNames: {page:null, rows:null, sort: “sidx”, order: “sord”, search:”_search”, nd:null}
etc.
With this way one receives most flexibility and shortest URLs with minimum code changing.
What is your opinion about it?
Best regards,
Oleg
P.S. Thank you for your time. All my posts are too long, sorry.
08:49
30/07/2009
OlegK said:
Post edited 15:47 – 16/08/2009 by OlegK
So my suggestion to remove nd parameter from the list of default parameters of prmNames properties stays actually.
Yes. Sorry if I wasnt clear on that.
Also note that you may want to include "Pragma: no-cache", "cache-control: must-revalidate", and "cache-control: no-cache" in addition to "cache-control: max-age=0".
This is mainly to deal with caches that may be between the client and the server. "Pragma: no-cache" is for http 1.0 caches (if any still exist). must-revalidate and no-cache are to prevent caches that have been configured to allow stale data from doing so (either should be sufficient, but just in case a cache understands one but not the other).
Also, intermediate caches aside, if you expect others to write code to fetch data from your server, and you just use the max-age header, they could use eg "cache-control: max-stale" in their request to allow the browser to not revalidate. must-revalidate or no-cache will prevent that. Of course, if you have control over both the client and server code, this isnt an issue (but the intermediate caches still are).
Mark
11:14
Moderators
30/10/2007
Hello Oleg,
Ende gut, alles gut
Also my first think when I read this post was to do something similar like you.
Now - this change is done.
Thanks
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
11:18
Moderators
30/10/2007
Hello Mark,
Yes, I think the most "important" things should be done server side without limiting it at client side.
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
50 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66