Export (0) Print
Expand All

NotModified 

Demonstrates how to send the Last-Modified response header and check for the If-Modified-Since request header to avoid generating a response body and transmitting data to the client unnecessarily.

Use a browser to view NotModified.srf and note the time at which the page was created (displayed in the page itself). Refresh the page and see if the creation date changes. If client-side caching is enabled in the browser, the page will not be updated until at least a minute has passed since the last version of the page was cached.

The server compares the value of the HTTP_IF_MODIFIED_SINCE request header with the current time. If less than 1 minute has passed, the server returns a 304 (Not Modified) status code without generating a response body. If more than 1 minute has passed, or the HTTP_IF_MODIFIED_SINCE header was not present in the request, the server generates the response in the standard way and sets the Last-Modified response header with the current server time.

Use the 304 (Not Modified) HTTP status code when:

  • The client has performed a conditional GET request.

  • Access to the resource is allowed.

  • The content cached by the client is up to date.

The benefit of this status code is that it allows the server to avoid generating a response body and transmitting that data to the client.

To make use of this status code:

  • Append a Last-Modified header and/or an ETag header to a successful (200 OK) response for this resource. This supplies the client with the information it needs to make conditional requests in the future.

  • Check the HTTP_IF_MODIFIED_SINCE and/or HTTP_IF_NONE_MATCH request headers. You should receive a request containing a HTTP_IF_MODIFIED_SINCE header if the client cached a response that contained a Last-Modified header. You should receive a request containing a HTTP_IF_NONE_MATCH header if the client cached a response that contained an ETag header.

  • Use HTTP_IF_MODIFIED_SINCE for time-based validation of the cached content.

  • Use HTTP_IF_NONE_MATCH for other validation of the cached content (the meaning of the ETag is decided by the server).

Demonstrates

Community Additions

ADD
Show:
© 2014 Microsoft