Principle analysis of Web site optimization using client-side Caching 1th/2 page _php tips

Source: Internet
Author: User
Many people would like to start with the server cache to start to optimize the program, many different server caching methods have their own characteristics, as I have been involved in some projects, according to the cache hit rate different use of com+/enterprise libiary caching/ Windows services, static files and other methods of server-side caching and HTTP compression technology, but the client cache is often overlooked, even if the server's cache makes your page access is very fast, but she still need to rely on the browser to download and output, and when you join the client cache, It will bring you a lot of benefits. Because she can cache the most visited pages in the site to fully improve the throughput of the WEB server (usually in the number of requests per second) to improve application performance and scalability.
A survey of online shopping shows that most people are willing to go to the store line, but are unwilling to wait while shopping online. The Websense survey company said up to 70% of internet users said they were unwilling to read for more than 10 seconds on the page. More than 70% of people will cancel the current order because the speed is too slow.


Basic knowledge
1 What is "last-modified"?

When the browser first requests a URL, the server-side return status is 200, the content is the resource you requested, and there is a last-modified attribute that marks the last time the file was modified at the service end, similar in format:

Last-modified:fri, May 2006 18:53:33 GMT

The second time the client requests this URL, according to the HTTP protocol, the browser sends the If-modified-since header to the server asking if the file has been modified after that time:

If-modified-since:fri, May 2006 18:53:33 GMT

If the server-side resources do not change, the HTTP 304 (not Changed.) Status code is automatically returned, and the contents are empty, thus saving the amount of data transferred. When the server-side code changes or restarts the server, the resource is issued again, similar to the first request. This ensures that resources are not duplicated to the client and that the client is able to get the latest resources when the server changes.

2 What is "Etag"?

The HTTP protocol specification defines etag as the entity value of the requested variable (see-section 14.19). Alternatively, ETag is a token (token) that can be associated with a Web resource. A typical web resource can be a Web page, but it may also be a JSON or XML document. The server is solely responsible for determining what the token is and what it means, and sending it to the client in the HTTP response header, the following is the format returned by the server side:

ETag: "50b1c1d4f775c61:df3"

The client's query update format is like this:

if-none-match:w/"50b1c1d4f775c61:df3"

If ETag does not change, it returns state 304 and does not return, as is the case with last-modified. I test etag mainly in the breakpoint download more useful.


How do last-modified and etags help improve performance?
Smart developers use the HTTP headers of last-modified and ETAGS requests, which can take advantage of caching by clients such as browsers. Because the server first generates a Last-modified/etag tag, the server can use it later to determine if the page has been modified. Essentially, the client requires the server to authenticate its (client) cache by passing the token back to the server.
The process is as follows:
1. Client requests a page (a).
2. The server returns page A and adds a last-modified/etag to a.
3. The client presents the page and caches the page along with the Last-modified/etag.
4. The Customer requests page A again and passes the Last-modified/etag returned by the server to the server together with the last request.
5. The server checks the last-modified or ETag and determines that the page has not been modified since the last client request, returning directly to response 304 and an empty response body.

The following example describes how to use server-side code to manipulate client caching:
Current 1/2 page 12 Next read the full text

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.