Disable IE and Firefox cache using php _ PHP Tutorial

Source: Internet
Author: User
Disable IE and Firefox cache using php. I found a lot of methods in the network speed, and finally solved the problem. The simplest method is to add the meta tag METAHTTP-EQUIVCache-ControlCONTENTno-cache, no-store, must-revalidateME found many methods in the network speed, and finally solved the problem.
In fact, the simplest way is to add Tag

You can also use program control

The code is as follows:

Header ("Cache-control: no-cache, no-store, must-revalidate ");
Header ("Pragma: no-cache ");
Header ("Expires: 0 ");

If Or header ("Cache-control: no-cache, no-store, must-revalidate"); if no-store is missing, Firefox's Cache cannot be solved.
The following is a detailed analysis:
Two important differences between Firefox and IE browser cache
After creating a WEB service, you usually need to configure two types of cache:
When the website is updated, html resources expire immediately so that users who are browsing can get updates quickly.
Set all other resources (examples, CSS, and javascript scripts) to expire after a certain period of time.
This cache solution covers some ideas about how to handle updates mentioned in Two Simple Rules for HTTP Caching.
Now HttpWatch 6.0 supports Firefox. we want to discuss the differences between Firefox and IE in processing cache. the method for setting a long Expiration Time (the second one above) can still be used directly in Firefox, but configuration 1 is slightly different between the two.
In the previous article, we divided the first article:
In some cases, the dynamic HTML page needs to be updated from the server immediately for display at any time-or even when the back button is used. for example, the status of the bank account or online order is displayed.
Static HTML pages, such as the contact, FAQs, or site map pages, can be used to cache if the Last-Modified response header is set for the browser to re-verify as needed.
The rest of this article discusses two important differences that affect HTML page caching in Firefox.

1. use no-cache to prevent invalid Firefox cache
You can set the following response header to prevent IE from caching anything:
Cache-Control: no-cache
The page with this response header is not saved in the cache, and IE is always loaded from the server again, even if you use the back button. the following example uses HttpWatch to listen to an online store. when we click the back button after submitting the order form, the result is as follows:

However, this response header cannot prevent Firefox caching. this means that Firefox will always use the cached page during normal access until it sends a GET request for re-verification. in addition, if you access the page through the back button, Firefox will not access the server again, but simply load it directly from the cache.

How Can I disable the cache in Firefox? The answer is simple. because Firefox relies on cached copies to perform operations such as "File-> save as" and "View Source Code. however, you can control where the page is cached and the cache entries can be used for display.
The following response header prevents persistent caching in Firefox and forces the page to be cached in memory:
Cache-Control: no-store
This header also prevents access to the cache page when the backend button is used. it triggers an http get request.
The combination of the two response header values can be expected in IE and Firefox:
Cache-Control: no-cache, no-store
The following HttpWatch response header label is shown:

2. If no expiration time is set, Firefox will set an http response for IE when there is no Expires header, it will think that the cache entry will never be used automatically until it is re-verified from the service. because a setting item of the temporary IE file "checks the newer version of the webpage" is "automatic" by default, it is usually a session.
This provides a reasonable way to control the cache of static html content. the new IE will get the latest html version, and the cached version will be used until IE is disabled.
Firefox uses different methods to process missing Expires headers. if the Last-Modified header is affected, it uses an expired retry value specified in the HTTP 1.1 standard RFC2616:
( Reference Specification:)
In addition, if there is a Last-Modified time value in the response, the retry expiration value cannot exceed the ratio between the value and the current time interval. Generally, this ratio is set to 10%.
The calculation method is as follows:
Expiration Time = current time + 0.1 * (time difference between Last-Modified and now)
For example, if the last modification time of your static HTML file is 100 days ago, the expiration time is 10 days later. the following example shows an HttpWatch cache tag without an Expires header page:
Firefox automatically sets the Expiration Time to 8 days later, because this page has not been modified for about 80 days.
This means that, to keep your HTML page under control, as we have discussed in the Two Simple Rules for HTTP Caching article, you 'd better serve your static resources such as HTML, images, CSS files, etc. set an appropriate Expires value on your WEB server.

To ensure that the cache behavior of IE is consistent with that of Firefox, you should:
Always specify an Expires header. general settings-1 use html pages to instantly refresh or set a specific expiration time for other slices, CSS, and javascript script resources
If you want to force page refresh or even click the background button, set Cache-Control: no-cache, no-store

In fact, the easiest way to add the meta tag META HTTP-EQUIV = "Cache-Control" CONTENT = "no-cache, no-store, must-revalidate" ME...

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.