Home > Web Front-end > JS Tutorial > body text

Detailed explanation of HTTP 304 error_Basic knowledge

WBOY
Release: 2016-05-16 17:15:51
Original
1464 people have browsed it

Not Modified The client has buffered documents and issued a conditional request (usually providing an If-Modified-Since header to indicate that the client only wants documents that are newer than the specified date). The server tells the client that the original buffered document can continue to be used.

If the client finds that the cached file has Last Modified when requesting a file, then the request will include If Modified Since , and this time is the Last Modified of the cached file. Therefore, if the request contains If Modified Since, it means that it is already cached on the client. Just judge this time and the modification time of the currently requested file to determine whether to return 304 or 200. For static files, such as CSS and images, the server will automatically compare Last Modified and If Modified Since to complete caching or updating. But for dynamic pages, which are dynamically generated pages, they often do not contain Last Modified information, so browsers, gateways, etc. will not cache them, that is, a 200 request will be completed every time they are requested.

Therefore, for caching acceleration of dynamic pages, you must first add the Last Modified definition to the HTTP Header of the Response, and then return 200 or 304 based on the If Modified Since in the Request and the update time of the requested content. Although a database query has been made when returning 304, more subsequent database queries can be avoided, and no page content is returned but only an HTTP header, thus greatly reducing bandwidth consumption and improving user experience.

When these caches are valid, viewing a request through HttpWatch will yield the following results:

First visit 200

Second access by mouse click (Cache)

Press F5 to refresh 304

Press Ctrl F5 to force refresh 200

If this is the case, it means that the cache is really effective. The above is my understanding of HTTP 304.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template