Jquery-ajax-cache
Source Address: Https://github.com/WQTeam/jquery-ajax-cache
jquery Plugins-caching jquery AJAX requests with ' localstorage ' and ' sessionstorage '.
Let's start by explaining what scenario you need to use to cache Ajax requests into localstorage. All know that the browser itself to the HTTP request is a cache policy, but this way of caching two defects: 1, can only cache GET request 2, while the cache settings are in the back end of the response of the message header specified. (PS: Many of the business code logic is now focused on the front end, so long as the front-end development is difficult to use this way to cache)
Now smartphones are supported H5, there is no need to consider the compatibility of old ie. Mobile Web development can be used in this way to cache Ajax requests and optimize the user experience.
Simple to use, as follows
Use
$ajaxCache. Config ({//business logic to determine whether the request is cached, RES returns results for Ajax cachevalidate:
function (
res) {//optional, configure global validation for how caching is required, "Global Configuration" and "Custom", There is at least one place to implement the Cachevalidate method return res.state === ' ok", / /optional, ' localstorage ' or ' sessionstorage ', default ' Localstorage ' Timeout: 60 * 60, //optional, units per second. Default 1 hours});
/span>
$. Ajax ({ //used whenever adding a single line to an AJAX request adds a property ajaxcache:true Ajaxcachetrue/ * Others ... */});
[Open source] jquery plugin, using ' localstorage ' to cache jquery Ajax, optimize page AJAX requests