Search

1/14/2009

Fiddler PowerToy - Part 2: HTTP Performance

Fiddler PowerToy - Part 2: HTTP Performance

When a resource is needed by the client, there are three possible actions:
* Send a plain HTTP request to the remote Web server asking for a resource
* Send a conditional HTTP request to the origin server asking for the resource only if it differs from the locally cached version
* Use a locally cached version of the resource, if a cached copy is available

When sending a request, the client may use one of the following headers:
Pragma: no-cacheThe client is unwilling to accept any cached responses from caches along the route and the origin server must be contacted for a fresh copy of the resource.
If-Modified-Since: datetimeThe server should return the requested resource only if the resource has been modified since the date-time provided by the client.
If-None-Match: etagvalueThe server should return the requested resource if the ETAG of the resource is different than the value provided by the client. An ETAG is a unique identifier representing a particular version of a file.

A client indicates that it has a cached response available for use by sending a "Conditional request" containing the headers If-Modified-Since or If-None-Match. If the server replies to a conditional request with HTTP/304 Not Modified, the client is directed to reuse its cached response. Otherwise, the server should return a new response and the client should discard its outdated cache item.

Observe two consecutive requests for an image file in the following code sessions. In the first session, no locally cached version of the file is present, so the server returns the file along with an ETAG value and the date-time of the last modification of the file. In the subsequent session, a locally cached version of the file is now available, so a conditional request is made, passing up the ETAG of the cached response as well as the Last-Modified time of the original request. Since the image has not changed since the cached version (either because the ETAG matches or the If-Modified-Since value matches the Last-Modified value) the server returns a 304 to the client to direct it to use the cached response.

Session #1

GET /images/banner.jpg HTTP/1.1
Host: www.bayden.com

HTTP/1.1 200 OK
Date: Tue, 08 Mar 2006 00:32:46 GMT
Content-Length: 6171
Content-Type: image/jpeg
ETag: "40c7f76e8d30c31:2fe20"
Last-Modified: Thu, 12 Jun 2003 02:50:50 GMT

Session #2

GET /images/banner.jpg HTTP/1.1
If-Modified-Since: Thu, 12 Jun 2003 02:50:50 GMT
If-None-Match: "40c7f76e8d30c31:2fe20"
Host: www.bayden.com

HTTP/1.1 304 Not Modified

SettingCache copy is freshCache staleNo cache-directives were present
Every visit to the pageNo requestConditional requestConditional request
Every time you start Internet ExplorerNo requestConditional requestConditional request
AutomaticallyNo requestConditional requestHeuristic (see below)
NeverNo requestConditional requestNo request

沒有留言: