Any Need 4 Far Future Headers?


#1

Hey all, I was wondering if there was any need to update the htaccess file at all to tell visitors to save the images for a little while.

Is it true that DreamHost somehow already automatically handles this? The reason I am thinking they may is because when I look at site statistics under status codes, code #304 Not Modified Since Last retrieval is very high for my static pages and images.

Also, with like 500 requests for a page in one day, the data transfer is only like 500kb for that day on average, when I know the average file size is like 10kb (which means I would expect 5MB per day).

So anyway, I was looking at YSlow, and they said the Far Futures stuff needs to be up. But does it really? Thanks a bunch for your input, as I really don’t understand if I need to go modify the htaccess file or not.


#2

If you want to get the best possible performance out of your site, then yes.

HTTP 304 (“Not Modified”) results are certainly faster than uncached (HTTP 200) results, since the web server doesn’t have to send any data to the browser, but the browser still has to make the request, so there’s still a network round-trip involved. If the original result includes an HTTP Expires header, the browser doesn’t need to contact the web server at all — it just uses data straight out of its cache.

There’s a downside to using Expires headers, though: if you change files on your web site, the browser will never know it until the expiration date arrives. As such, Expires should be reserved for files which you don’t expect to change on short notice.

Incidentally, Expires headers are a significant part of what makes this forum feel so fast. Pretty much every resource other than the main HTML pages are cacheable, so your browser can start rendering the page as soon as it receives data.


#3

Ahh ok. Does anyone know where I can find a step by step tutorial for how to modify the htaccess file on dreamhost to basically remember 1 image in my images folder for 1 month before it needs to refresh it? I don’t even know where to find the file, and I think the last time i tried to modify one I didn’t have a a program that would let me do it.

Also, I only use an index.html and 3 images. the expires thing should work perfectly for this?

Thanks a bunch for your guidance.


#4

If all you have is a single index.html page, I wouldn’t bother with Expires headers. They’re mainly useful for larger sites where there’s a good chance that a visitor will look at many pages in a session and/or return to your site. With only one HTML page, the benefits you’re likely to see are pretty minimal.

That being said, here’s the official documentation:

http://httpd.apache.org/docs/2.2/mod/mod_expires.html

What you’ll need in an htaccess file, at the minimum, is something like:

ExpiresActive on <FilesMatch "\.(gif|jpe?g|png|css|js)$"> ExpiresDefault "access plus 2 weeks" </FilesMatch>


#5

I’ll take your advice. Thank you very much for your help. I really appreciate it guys.

BTW, where can I find the htaccess file? And then, how do you edit one? Is there a special program?


#6

Your site might not have a .htaccess file, but you can make your own:
http://wiki.dreamhost.com/Htaccess