Caching images on a website

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DWalley
    Junior Member
    • Jul 2004
    • 25

    Caching images on a website

    Is there any way to cache images on a site so they dont reload everytime the page is accessed?
    My bandwidth is climbing in the images usage.
  • Frank Hagan
    Senior Member
    • Mar 2004
    • 724

    #2
    Originally posted by DWalley
    Is there any way to cache images on a site so they dont reload everytime the page is accessed?
    My bandwidth is climbing in the images usage.
    I could be wrong on this, but I think caching would only work to speed up the transfer of bytes from the server to your visitor's browser. The image size would be the same in the cache as it is on disk, and you are sending that same number of bytes to the user's browser ... just faster.

    Check your AWStats to see if you are being visited by Google's image search bot. I found they were using more bandwidth than my users. And I don't really want the images on my site indexed by Google anyway. So in my robots.txt file (placed in public_html) I added the lines:

    User-agent: Googlebot-Image
    Disallow: /

    And Google will stop indexing images.

    Comment

    • DWalley
      Junior Member
      • Jul 2004
      • 25

      #3
      Thanks Frank, I will look but I cant be sure if it was bots or people. In 3 days I had 14000 hits on images. Hard to believe it is people.

      Comment

      • djn
        Senior Member
        • Mar 2004
        • 140

        #4
        One thing you may try is telling the visiting browsers to cache the images on their side avoiding repeated requests.
        This is what I use (goes into .htaccess):

        <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault A18000
        ExpiresByType image/gif A2592000
        ExpiresByType image/jpeg A2592000
        ExpiresByType image/png A2592000
        ExpiresByType text/css A604800
        ExpiresByType text/javascript A604800
        </IfModule>

        It would help if we could also control cache-enabling headers to the various downstream caches (ISPs, corporate gateways and such) but as far as I can tell this woul require the mod_headers module to be enabled, which is not the case at DIS - I believe (mod_header instructions in .htaccess gave a server error, last time I tried). Hint: Andrew, would you thing about this? It's not some exotic module - mod_headers has been around for some time now...

        Comment

        • DWalley
          Junior Member
          • Jul 2004
          • 25

          #5
          ExpiresByType image/png A2592000

          what do the letters and numbers after png represent?

          Comment

          • djn
            Senior Member
            • Mar 2004
            • 140

            #6
            It tells the browser to keep the image for a month (written in seconds) - A means start counting at download time, while M would have meant since "Last-Modified".
            The Apache docs explain it well at:

            Comment

            Working...