jqGrid data stored in browser cache?
Asked Answered
S

1

1

Does jqGrid store grid data on the file system? If so, do you need to clear the browser's cache to remove it?

Or is it just stored in memory by JavaScript (and the browser)? Would just closing your browser remove the data?

Do the answers to these questions change depending on whether you are using loadOnce?

Sufficient answered 7/10, 2010 at 20:34 Comment(0)
C
4

Per default the data loaded from the server (JSON or XML data) will be saved in the browser cache, but not used at the next request. The reason is that per default jqGrid implement the same behavior of ajax requests like cache:false parameter of jQuery.ajax. It means that all requests has an additional parameter nd like nd=1286296925096 which is the timestamp. It makes the URL of all GET requests unique and so the local saved data will not used twice. So if you want that jqGrid not use the data from the local browser cache you need to do nothing.

If you want additionally deny saving the data locally (for example because of security reason or to reduce filling of the local cache with the information which will never used) you can include no-store directive in the HTTP header of the server response.

If you do want to cache the server requests and use the data you should prmNames: { nd:null} jqGrid option. Then the data from the next requests could be get from the local browser cache. If you do this I'll recommend you include in the HTTP header of the server response the Cache-Control directives which force to use the caching behavior which you need. For example I use personally Cache-Control: max-age=0 and use ETag with the hash from the data sent. So all ajax requests will be sent to the server to revalidate the local cache. All the requests will be automatically contain If-None-Match HTTP header with the ETag of the data from the local cache. If the data are not changed the server can answer with the response HTTP/1.1 304 Not Modified having no body instead of HTTP/1.1 200 OK with the body having the data. The response HTTP/1.1 304 Not Modified allows the browser to use the local cache.

UPDATED: I use additionally Cache-Control: private which switch off caching the data on the proxy and declare that the data could be cached, but not shared with another users.

If you want read more about caching control with respect of HTTP headers I'll recommend you to read the following Caching Tutorial.

Chambers answered 7/10, 2010 at 21:18 Comment(3)
what if we dont use HTTP header? I used only prmNames: { nd:null} and its working perfectly as I was looking for.Tubercular
@Jaikrat: I don't understand the statement "what if we dont use HTTP header?" Every URL which start http://... will use HTTP protocol to load the corresponding HTML page. You can use Fiddler or Developer Tools of IE/Chrome (press F12 to start and to the Network tab) to make Network trace (to be exactly it's HTTP trace). If you use prmNames: { nd: null } and mtype: "GET" then you could have problems in Internet explorer (especially old versions) because it will cache old requests and will send no new requests to the server.Chambers
@Jaikrat: So I recommend to set HTTP header Cache-Control: private, max-age=0 in the server response. Additionally one can use prmNames: { nd: null } to remove absolutely unneeded parameter. The Cache-Control is part of HTTP standard and all web browsers will send new Ajax request to the server instead of just getting previous request from web browser cache. It's the most clean way.Chambers

© 2022 - 2024 — McMap. All rights reserved.