How to use PHP to disable IE and Firefox cache problems

Source: Internet
Author: User
The use of PHP to disable the Internet Explorer and Firefox cache problem, in the Internet to find a lot of methods, and finally solved, need to know the friend can refer to the next

In the Internet to find a lot of ways, and eventually solved the
In fact, the simplest way is to add <meta> tag to the head
<meta http-equiv= "Cache-control" content= "No-cache,no-store, must-revalidate" >
<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Expires" content= "0" >
You can also use program control

<?php header ("Cache-control:no-cache,no-store,must-revalidate"); Header ("Pragma:no-cache"); Header ("expires:0");?>

If in <meta http-equiv= "Cache-control" content= "No-cache,no-store, must-revalidate" > or Header ("Cache-control: No-cache,no-store,must-revalidate "); No-store will not solve Firefox's cache.
Here's a specific analysis.
two important differences between Firefox and IE browser cache
When you establish a good one Web service, there are typically two types of caches that need to be configured:
The HTML resource expires immediately when the site is updated so that users who are browsing can be updated quickly.
Set all other resources (examples, css,javascript scripts) to expire after a certain amount of time.
This caching scheme covers a few ideas about how to handle updates in the caching article for HTTP.
Now that HttpWatch 6.0 supports Firefox, we want to talk about how Firefox differs from IE in dealing with cache. Setting the usage of a longer expiration time (the second above) can still be used directly in Firefox, but configuration 1 has subtle differences between the two.
In the previous articles, we divided the first article into:
Sometimes dynamic HTML pages need to be updated instantly from the server for display at any time-even when using the back button. For example, displays the status of a bank account or an online order.
Static HTML pages, such as Contacts, FAQs, or site maps, can be used to cache if they have a last-modified response header that allows the browser to re-verify when needed.
The rest of this article explores two important differences in Firefox that affect HTML page caching.

1. Use No-cache to prevent Firefox cache from invalidating
You can simply set the following response header to prevent IE from caching anything:
Cache-control:no-cache
Pages that use this response header are not saved in the cache, IE will always reload from the server, even if you use the Back button. The following example uses HttpWatch to listen to an online store, and when we click the Back button after submitting the order form, the results are as follows:

However, this response header does not prevent Firefox from caching. This means that Firefox will always use the cached page in the case of normal access until it sends a GET request to re-verify. And, if you access the page via the Back button, Firefox will not access the server again. Instead, it is simply loaded directly from the cache.

So how do you turn off the cache in Firefox? The answer is very simple and cannot be closed. Because Firefox relies on the copy in the cache as "file-Save as", "view source" such as the operation of the service. However, you can control where the page caches and those cache entries can be used for display.
The following response header in Firefox prevents persistent caching, forcing the page to be cached in memory:
Cache-control:no-store
This header also prevents access to the cache page when the back button is used, which triggers an HTTP GET request.
The combination of the values of these two response headers uses the results that can be expected in IE and Firefox:
Cache-control:no-cache, No-store
As shown in the HttpWatch Response header label:


2If you do not set an expiration time Firefox will set you an HTTP response when IE encounters no expires header, and it will assume that the cache entry will never be automatically used until it is re-verified from the service. Due to a setup entry for the temporary file of IE, "Check for newer versions of Web pages" defaults to " Automatic ", so it is usually done one session at a time.
This provides a reasonable way to control the caching of static HTML content. The user's newly opened IE will get the latest version of HTML, and the cached version will be used until IE is closed.
Firefox handles missing expires headers in different ways. If the impact has last-modified headers it will use one of the attempted expiration values specified in the HTTP 1.1 specification RFC2616:
(Reference Specification:)
Also, if there is a last-modified time value in the response, the attempted expiration value cannot exceed this value to a ratio of the current time interval, which is typically set at a rate of 10%.
The method is calculated as follows:
Expiry time = Current time + 0.1 * (last-modified to current difference)
For example, if your static HTML file was last modified 100 days ago, the expiration time is 10 days later. The following example is a HttpWatch cache label that does not have a expires header page:
Pic3
Firefox automatically sets the expiration time to 8 days, because this page has not been modified for about 80 days.
This means, in order to keep control of your HTML page, as we discussed in the two simple Rules for HTTP caching article, you'd better for your static resources such as HTML, pictures, CSS files, etc., Set an appropriate expires value on your Web server.

Conclusion
To ensure that IE is consistent with Firefox's caching behavior, you should:
Always specify a expires header. General Settings-1 use HTML pages to instantly refresh or set a specific expiration time on other slices, css,javascript script resources
If you want to force the page to refresh, even when you click the Background button, then set Cache-control:no-cache, No-store

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

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.