Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
No caching of server data because of new nd property in prmNames
13/08/2009
04:58
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

13/08/2009
05:21
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

13/08/2009
05:41
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

15/08/2009
09:52
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

16/08/2009
02:51
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

Note that you can turn off caching via headers, and doing it this way has a significant advantage over the nd approach:

You can still use ETag to return a "304 Not Modified" response from the server. With the nd parameter you never get that opportunity.

Mark

16/08/2009
15:47
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

17/08/2009
06:54
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

17/08/2009
16:40
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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.Confused

18/08/2009
08:49
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

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

18/08/2009
11:14
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Oleg,

Ende gut, alles gut Wink

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.

18/08/2009
11:18
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information