Cache-control use Cache-control: private learning notes

Source: Internet
Author: User
Tags http authentication

The function of browser review is divided into the following situations:
(1) open a new window
If the values are private, no-cache, and must-revalidate, the server will be accessed again when a new window is opened.
If the max-age value is specified, the server will not be accessed again within the time range. For example:
Cache-control: max-age = 5 (indicating that the server will not be accessed again within 5 seconds after the webpage is accessed)

(2) Press enter in the address bar
If the value is private or must-revalidate, the server will be accessed only during the first access and will not be accessed in the future.
The value is no-cache.
If the value is max-age, the access will not be repeated before expiration.

(3) press the button to return
If the values are private, must-revalidate, and max-age, no re-access is performed,
If the value is no-cache, access is repeated each time.

(4) refresh the button
No matter what the value is, it will be accessed again
When the Cache-control value is "no-cache", accessing this page does not leave page backup in the temporary article folder on the Internet.
In addition, specifying the "Expires" value also affects the cache. For example, if you specify the Expires value as a time that has passed, if you repeatedly press enter in the address bar when accessing this network, the access will be repeated at: Expires: Fri, 31 Dec 1999 16:00:00 GMT
For example, disable page caching in IE.
Http Response Message Header settings:

Copy codeThe Code is as follows: CacheControl = no-cache
Pragma = no-cache
Expires =-1

Expires is a good stuff. If the webpage on the server changes frequently, set it to-1, indicating that it will expire immediately. If a webpage is updated at every day, you can set Expires to the next day.
When CacheControl = no-cache is specified on the HTTP1.1 server, the browser does not cache the webpage.

The Cache-Control title cannot be used for legacy HTTP 1.0 servers.

To be backward compatible with HTTP 1.0 servers, IE uses the Pragma: no-cache title to provide special support for HTTP.
If the client communicates with the server through a secure connection (https: //) and the server returns the Pragma: no-cache title in the response,
Internet Explorer does not cache this response. Note: Pragma: no-cache prevents caching only when used in secure connections. If used on a non-secure page, the processing method is the same as Expires:-1, this page will be cached but marked as expired immediately.

Common header commands
The header is divided into three parts:
The first part is the HTTP Version );
The second part is the Status code );
The third part is the Reason Phrase (Reason-Phrase ).

Copy codeThe Code is as follows: <? Php
// Fix 404 pages: use this header command to solve the 404 header generated by URL rewriting.
Header ('HTTP/1.1 200 OK ');

// Set 404 header: Page not found
Header ('HTTP/1.1 404 Not Found ');

// The page is permanently deleted. You can tell the search engine to update their urls.
// Set Moved Permanently header (good for redrictions)
// Use with location header
Header ('HTTP/1.1 301 Moved Permanently ');
// Restricted access
Header ('HTTP/1.1 403 Forbidden ');
// Server error
Header ('HTTP/1.1 500 Internal Server error ');

// Redirect to a new location
// Redirect to a new location:
Header ('location: http://www.jbxue.com );

Redirection after a delay of some time
// Redrict with delay:
Header ('refresh: 10; url = http://www.sina.com.cn ');
Print 'you will be redirected in 10 seconds ';

// Overwrite X-Powered-By value
// Override X-Powered-By: PHP:
Header ('x-Powered-By: PHP/4.4.0 ');
Header ('x-Powered-By: Brain/0.6b ');

// Content language (en = English)
// Content language (en = English)
Header ('content-language: en ');

// The last modification time (which can be used in cache)
// Last modified (good for caching)
$ Time = time ()-60; // or filemtime ($ fn), etc
Header ('Last-Modified: '. gmdate ('d, d m y h: I: s', $ time). 'gmt ');

// Tell the browser that the content to be retrieved has not been updated
// Header for telling the browser that the content
// Did not get changed
Header ('HTTP/1.1 304 Not modified ');

// Set the content length (which can be used for caching ):
// Set content length (good for caching ):
Header ('content-Length: 1234 ');

// Used to download an object:
// Headers for an download:
Header ('content-Type: application/octet-stream ');
Header ('content-Disposition: attachment; filename = "example.zip "');
Header ('content-Transfer-Encoding: binary ');

// Disable caching the current document:
// Load the file to send: readfile('example.zip ');
// Disable caching of the current document:
Header ('cache-Control: no-Cache, no-store, max-age = 0, must-revalidate ');
Header ('expires: Mon, 26 Jul 1997 05:00:00 gmt ');
// Set the content type:
// Date in the pastheader ('pragma: no-cache ');
// Set content type:
Header ('content-Type: text/html; charset = iso-8859-1 ');
Header ('content-Type: text/html; charset = UTF-8 ');
Header ('content-Type: text/plain ');

// Plain text file
Header ('content-Type: image/jpeg ');

// JPG picture
Header ('content-Type: application/zip ');

// ZIP file
Header ('content-Type: application/pdf ');

// PDF file
Header ('content-Type: audio/mpeg ');

// Audio MPEG (MP3,...) file
Header ('content-Type: application/x-shockwave-flash ');

// The logon dialog box is displayed for HTTP authentication.
// Flash animation // show sign in box
Header ('HTTP/1.1 401 unauthorized ');
Header ('www-Authenticate: Basic realm = "Top Secret "');
Print 'text that will be displayed if the user hits cancel or ';
Print 'enters wrong login data ';
?>

Now we can use AJAX to verify the form and prompt users at any time. However, when the user does not pay attention to the AJAX friendly prompt, the user submits an incorrect form and jumps back to the original page, all information entered is lost.
To support page bounce, you can do the following:
1. Use the session_cache_limiter method: session_cache_limiter ('Private, must-revalidate '). However, it is worth noting that the session_cache_limiter () method must be written before the session_start () method;
2. Use the header to set the Cache control Method: header ('cache-control: private, must-revalidate ');

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.