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.