Slashdot Mirror


Speed Up Sites with htaccess Caching

produke writes "Increase your page load times and save bandwidth with easy and really effective methods using apache htaccess directives. mod_headers to set expires, and max-age, and cache-control headers on certain filetypes. The second method employs mod_expires to do the same thing -- together with FileETag, makes for some very fast page loads!"

11 of 29 comments (clear)

  1. Increase page load times? by daranz · · Score: 5, Funny

    Why would I want to do that?

    --
    This is a sig. It is appended to the end of comments I post.
    1. Re:Increase page load times? by grommit · · Score: 2, Funny

      Maybe you'd like to increase page load times to make your site behave like a Web 2.0 (3.0?) site so you can get some investor to give you truckloads of money?

  2. I use it all the time, but be aware.. by slashkitty · · Score: 5, Interesting
    It works great for images. I remember when I first started using it. It cut the number of http requests to the server in 1/2, and substantially reduced the bandwidth usage.

    However, if you are one to be changing images around, like using a Holiday logo or something, you have to change the image file name to force browsers to reload it.

    I'm sorta surprised that slashdot doesn't use this on their images:

    wget -S --spider http://images.slashdot.org/logo.png
    --08:31:01-- http://images.slashdot.org/logo.png
    => `logo.png'
    Resolving images.slashdot.org... 66.35.250.55
    Connecting to images.slashdot.org|66.35.250.55|:80... connected.
    HTTP request sent, awaiting response...
    HTTP/1.0 200 OK
    Date: Mon, 04 Dec 2006 14:30:12 GMT
    Server: Boa/0.94.14rc17
    Accept-Ranges: bytes
    Cache-Control: max-age=43200
    Connection: Keep-Alive
    Keep-Alive: timeout=10, max=1000
    Content-Length: 7256
    Last-Modified: Fri, 01 Dec 2006 03:02:14 GMT
    Content-Type: image/png
    Length: 7,256 (7.1K) [image/png]
    200 OK

    --
    -- these are only opinions and they might not be mine.
  3. caching htaccess? by oneiros27 · · Score: 4, Informative

    Here I was, thinking that someone had a solution for the slowdown caused by using htaccess files in the first place.

    They don't.

    If you're going to set caching in your server to decrease load time, make sure to set in the main configuation files, and disable htaccess, which can potentially increase the time of every page load. (the decreased hits and bandwidth may be an advantage to you -- you'll have to benchmark to see if this solution helps or hurts you for your given platform and usage patterns)

    --
    Build it, and they will come^Hplain.
    1. Re:caching htaccess? by mwvdlee · · Score: 2, Interesting

      On shared hosting, which most (smaller) sites use, you typically don't have access to the server configuration files. I have a shared hosted site and I'm definitly going to implement this for images and other static files.

      What is the performance loss in htaccess files anyway? For instance, would it be faster to have htaccess redirect moved pages or would it be faster to have a server-side script (i.e. php, python, etc.) do redirecting?

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
  4. httpd.conf by Nos. · · Score: 5, Informative

    Its in the comments on that site, but remember, you're always better off putting this kind of stuff in your httpd.conf as opposed to .htaccess files. htaccess files reduce performance on your webserver.

    1. Re:httpd.conf by bcat24 · · Score: 3, Informative

      Unless you're on a shared hosting plan. Then you kind of need to go with .htaccess.

  5. So using cache control headers is "news", huh? by xxxJonBoyxxx · · Score: 3, Informative

    So using cache control headers is "news", huh?

    Also, from the comment on this "innovative" article:

    1.DrBacchus said:
    Yes, these techniques *can* result in performance improvements, but should be put in your main server configuration file, rather than in .htaccess files. .htaccess files, by their very nature, cause performance degradation on your website, and so should be avoided whenever possible.

    1. Re:So using cache control headers is "news", huh? by mrsbrisby · · Score: 3, Insightful
      .htaccess files, by their very nature, cause performance degradation on your website, and so should be avoided whenever possible.
      NO! .htaccess files by their implementation cause performance degradation. The Apache group could have made that degradation zero, but thought that a Novell Netware port was more important.

      Seriously, Linux's F_NOTIFY has been around since 2.4 and other operating systems have similar.
    2. Re:So using cache control headers is "news", huh? by Trogre · · Score: 2, Informative

      I'm interested in this. Can you please elaborate and point me to the relevant discussion or, even better, a patch?

      --
      "Nine times out of ten, starting a fire is not the best way to solve the problem." - my wife
  6. htaccess performance loss by oneiros27 · · Score: 3, Informative

    If you're on a shared hosting site, and htaccess is already turned on, you're already affected.

    Basically, if someone were to request a file from your site: /this/is/some/deep/file

    Then apache has to look for, and if there, parse, each of the following files: /.htaccess /this/.htaccess /this/is/.htaccess /this/is/some/.htaccess /this/is/some/deep/.htaccess

    And then, should the rules allow the file to be served, it'll be sent to the requestor.

    So the problem isn't the .htaccess file itself (unless you have a whole bunch of unnecessary rules, increasing the size of the file), but just turning on support for .htaccess files. I think the parsing of the .htaccess files is cached, but the system still has to check for the files each time, and see if they've changed.

    As for question about redirects -- you have to tell the system how to process the 404s ... I've seen lots of implementations, including setting a template system to resolve all 404s, and then using the path requested to drive a template system ... which of course meant that _every_ page on the site was served as a 404. (I was given the task of trying to figure out what the person had done, as they had tried upgrading the site, and wanted to archive the old site, and it took me much longer than expected to figure out what the horrible hack was that they used. (and of course, no services had cached the site, so I could see what it used to look like, because it always served 404s)) ... unless you have some way of specifying a handler for 404 errors without .htaccess (which you don't, as you've mentioned it's shared hosting), the question about .htaccess makes no sense.... it's still getting called, and you're still taking the performance hit, no matter what you pass off to.

    --
    Build it, and they will come^Hplain.