Web Development JS---Page caching, JSP caching, HTML caching, Ajax caching, workarounds

Source: Internet
Author: User

About page caching issues. This problem has been found on the internet a lot. But found that all kinds of solutions, are separated from each other, there is no unified solution, I recently, also encountered the problem of page caching, according to the Web page cache of the answers to do a summary.

1. Server-side caching issues to prevent JSP page caching:

[Java]View Plaincopy
  1. <%
  2. Set the expiration date to a past time
  3. Response.setheader ("Expires", "Sat, 6 May 1995 12:00:00 GMT");
  4. Set http/1.1 No-cache Header
  5. Response.setheader ("Cache-control", "no-store,no-cache,must-revalidate");
  6. Set IE extension http/1.1 no-cache headers, users add themselves
  7. Response.AddHeader ("Cache-control", "post-check=0, pre-check=0");
  8. Sets the standard http/1.0 No-cache header.
  9. Response.setheader ("Pragma", "No-cache");
  10. %>

Of course, each page contains this code, which can be cumbersome to handle related pages by means of a custom filter

2. Prevent HTML page Caching

[XHTML]View Plaincopy < param name= "wmode" value= "Transparent" >
    1. <meta http-equiv= "pragma"  content= "No-cache" >  
    2. <meta http-equiv=< Span class= "Attribute-value" > "Cache-control"  content= "No-cache" >  
    3. <meta  Http-equiv= "expires"  content= "0" >     

3. Preventing AJAX Caching

If, your page, has been set to prevent jsp,html page cache, but found that the page cache, always exists, it is necessary to consider whether the Ajax caused by the page cache.

1) set, such as after

The AJAX cache is generated for the following reasons: request, URL address:
In IE, if the URL submitted by XMLHttpRequest is the same as history, the cache is used and is not submitted to the server side at all. Therefore, the data that was just submitted cannot be taken.

For Ajax, the following settings are required:

Method One: add timestamp var url = BaseURL + "&timestamp=" + New Date (). GetTime ();
Method Two: Plus random number var url = BaseURL + "&r=" + math.random ();

Summary: Original citation (http://www.javaeye.com/topic/150162)

In JSP pages, it is not possible to disable caching by using the HTML <meta> tag alone. Be sure to add

Response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Response.setdateheader ("Expires", 0);

Some people will say that this is not the same as the HTML tag settings. Indeed, I also think, but the practice proves that, without these words, just rely on HTML tag.

So when the action returns to the page, there are two things:

A, the returned page is not written on the above Forbidden cache statement (or only HTML tag is written). IE stores the URL link + page result (cache eabled). That's why we had the cache before.

b, the returned page is written with a forbidden cache statement. IE stores the URL link + page result (cache disabled). So that we can achieve the purpose we want. The request is actually sent every time.

Summary: Page cache does not have a unified solution, to specific problems specific analysis.

http://blog.csdn.net/oklzh/article/details/4445722

Http://www.blogjava.net/JAVA-HE/archive/2008/11/25/242420.html JS Write ()

Web Development JS---Page caching, JSP caching, HTML caching, Ajax caching, workarounds

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.