Browser caching problems using jquery in MVC

Source: Internet
Author: User

jquery in the browser Ajax calls, the cache provides a good support, post can not be cached,
The reason for using post is that the data cannot be cached or the JSON attack is avoided (JSON can be hacked when it returns data)

Ajax in the global object provides some ways to support caching and conditionalgets functionality

  $.ajax ({        ifmodified:true,        cache:true,    });

The ifmodified option defines whether the conditional get function is supported when Ajax calls, and jquery automatically handles the header value returned by the server named Last-modified.
It first requests the server to re-verify the entry using the Conditionalgets feature, and if the server returns a status code 304,jquery will reuse the entry in the cache.
Cache option: If False,jquery is appended with a timestamp after the requested URL to differentiate the previous URL address, so that each request is new, the requested data is definitely new

However, if the server explicitly defines that the response response cannot be cached, jquery is useless, and the cache option is ignored in the AJAX server, with the following disabled caches:

  // Disable Caching   Response.Cache.SetCacheability (Httpcacheability.nocache);


Server and client use conditional to verify cache data
The client places the entry in the cache, re-verifies after expiration, and the server must implement the conditional gets function (using Etags or Last modified header

JS Code

  $.ajax ({        ifmodified:true,// This is the key        true,        Success:function (DATA,STATUS,XHR) {        }    });

Server code:

  if (request.headers["if-modified-since"null  )            {                  Returnnew httpstatuscoderesult ((int) httpstatuscode.notmodified);            }

Browser caching problems using jquery in MVC

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.