Large concurrent Server Prerequisite technology: HTTP Caching

Source: Internet
Author: User
Tags header

The technology set up above is the server side of a person in the effort, and sometimes need to cooperate with the client.

A link request process can be roughly divided into several phases

If the client sends the same request, and the result is the same, can we buffer it? Is it possible to reduce the number of steps?

Yes, in general, there are a few ways to do this:

1. We first try to buffer on the service side, we try to send the content of a long link has been returned without release, the next request directly back to send the content, this does not apply to frequent access, for a number of special situations, special requests.

2. For static files have the last modification time LastUpdateTime, the first time the client requested the return HTTP header contains this lastupdatetime, then the client will add the page to the cache, the second request header contains LastUpdateTime, The service side compares it to the current lastupdatetime, and if so, directly tells the client that the file has not been modified, directly in your cache.

In fact, the field of HTTP return header save update time is last-modified, and the field of the request header is If-modified-since

Such as

Return header

http/1.1 OK

Date:wed, Mar 2013 07:35:22 GMT

content-type:text/html; Charset=utf-8

Content-encoding:gzip

Last-modified:wed, Mar 2013 07:35:22 GMT

Transfer-encoding:chunked

Server:yumeiz

Request Header

get/http/1.1

Host:www.xxx.com

Connection:keep-alive

If-modified-since:wed, Mar 2013 07:35:22 GMT

Return to Baotou again:

http/1.1 304 Not Modified

For some dynamic requests without modification time, the server can contract a field, and when the second request finds that the field has not changed, it also tells the client to use the content directly in the cache.

In fact, this field is ETag, and the field of the request header is If-none-match

Such as

Return header (only point to corresponding field, others consistent with above)

Etag= "ABCD"

Request Header

if-none-match=w/"ABCD"

Through the above we know that when the client received a 304 not Modified Baotou, it means you can directly use the cached pages, for some frequently requested files such as JS,CSS has a small role, there are some large image files, means to send a life-saving road grass ...

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.