Detailed explanation of HTTP 304 Errors _ Basics

Source: Internet
Author: User

The not Modified client has a buffered document and makes a conditional request (typically providing a if-modified-since header that indicates that the customer wants to update only a document that is newer than the specified date). The server tells the customer that the previously buffered document can continue to be used.

If the client finds that the file it caches has last Modified when it requests a file, then the request contains an If Modified Since, which is the last Modified of the cached file. Therefore, if the request contains an if Modified Since, it indicates that there is already a cache on the client. You can determine whether to return 304 or 200 as long as you judge the time and the current requested file's modification time. For static files, such as CSS, pictures, the server will automatically complete the comparison of last Modified and If Modified Since, complete the cache or update. But for dynamic pages, is dynamically generated pages, often does not contain the last Modified information, so that browsers, gateways and so do not do caching, that is, every time a request to complete a 200 request.

Therefore, for a dynamic page cache acceleration, first add the last Modified definition in the HTTP Header of the Response, and then return 200 or 30 according to the If Modified Since in Request and the update time of the requested content. 4. Although the return of 304 has done a database query, but can avoid the next more database query, and did not return the page content but only an HTTP Header, which greatly reduce the consumption of bandwidth, the user's feeling is also improved.

When these caches are valid, viewing a request through HttpWatch will result in this:

First visit 200

Mouse clicks two times access (Cache)

Press F5 to refresh 304

Press Ctrl+f5 to force refresh 200

If this is the case, the cache really works. The above is my understanding of HTTP 304.

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.