当前位置: 代码迷 >> Web前端 >> Zz jqGrid data stored in browser cache
  详细解决方案

Zz jqGrid data stored in browser cache

热度:793   发布时间:2012-09-10 11:02:32.0
Zz jqGrid data stored in browser cache?

The original article is in http://stackoverflow.com/questions/3885658/jqgrid-data-stored-in-browser-cache

?

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 .

  相关解决方案