Don’t panic. Error 304 is your friend.

If you’re running (or using) an Apache web server, there are two log files which are extremely useful for monitoring the health of your website. These are the Access Log and the Error Log.

When a page is served correctly, you’ll normally see a log line like this one:

66.249.66.175 - - [08/Jul/2008:23:40:23 +1000]
"GET /images/buttons/home.jpg HTTP/1.1" 200 15371

The group of numbers at the start of the line is the IP address of the remote computer, requesting a web page, file or image from your server. The next two hyphens are sometimes filled by a username, if the requested file or directory is protected (for example, by a .htaccess file). The date, time and timezone information come next, followed by the actual request sent by the remote computer’s browser. In this case, the remote browser is requesting (GET) an image, “home.jpg” which Apache tells us is 15,371 bytes-worth of information. This was sent successfully (code 200).

If a requested file doesn’t exist, that code 200 will be replaced by the well-known Error 404 – File Not Found. In this case a corresponding line would be written in the Error Log.

Keeping a close eye on my web server logs, I noticed a large number of requests which were answered with an Error 304, like this:

66.249.66.175 - - [09/Jul/2008:00:32:38 +1000]
"GET /sitemap.xml HTTP/1.1" 304 -

I’d never seen an Error 304 in a web browser, and I couldn’t understand why this was being issued. Time to do some research.

Error 304 is an error level rather than an actual error, much like the code 200. This code means “Page Not Modified”. Apache is returning this code to a web browser, and to save on bandwidth, tells the web browser that the page (or sitemap file in this instance) hasn’t been modified and to use cached data instead.

When the web browser sends its GET request, it also sends the date and time that it (the web browser) last loaded or cached the file. If Apache knows that it hasn’t been modified since this date and time, it returns a code 304, instead of the same page all over again. So the browser ends-up displaying just what it’s got cached. Cool huh?

Of course if the file had been modified, Apache would return a code 200 to the browser along with the new file.

Here’s some more reading for those interested:

Add Comment Register



Leave a Reply