[Open source] jquery plugin, using ' localstorage ' to cache jquery Ajax, optimize page AJAX requests

Source: Internet
Author: User
Tags sessionstorage

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.