Cache-control use cache-control: private learning notes

Source: Internet
Author: User
Tags http authentication
The webpage cache is controlled by the cache-control in the HTTP message header. common values include private, no-cache, Max-age, must-revalidate, etc. The default value is private http://www.jb51.net/article/34017.htm.

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 the Code 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 the Code 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 ');

Cache-control use cache-control: private learning notes

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.