How to remove images from cache on the Apache side

Posted on 2009-02-11
Last Modified: 2012-05-06
I have a simple PHP based application on Linux and Apache.

Recently I changed the Logo on home page , but unfortunately the old log image is still rendered and the users have to do a Ctr+f5 to remove the cache to get the new Image.

Is there a way I can remove the cached images on the server side do that the users dont get the old images and dont have to do the ctr+5
Question by:micro_learner
    LVL 27

    Expert Comment

    Change the filename.

    > that the users dont get the old images

    They don't get them, the browser displays a local cached copy without requesting the image from the server. Otherwise they'd get a fresh copy since the request header If-Modified-Since doesn't match anymore, so the server wouldn't reply with 304 not modified anymore.

    Author Comment

    Thats a great suggestion ..thank you ...but I am using a CMS drupal and that darn stuff has a lot of code ..anyother work around ?
    I restarted the apache too ..but dint seem to work ..
    Thanks for the nifty suggestion though.
    LVL 27

    Expert Comment

    That's on the client side, if the browser doesn't re-request the image but just displays it from disk cache, you can't do something on server side but change the referenced name to force the browser to load that resource from the server. Adding a (useless) QueryString to the image path should be enough. If that's not practicable due to the cms structure I can't see a way to force the browser to reload an already cached resource.

    But the cache should expire in some time which will lead the browser to re-request that resource from the server.
    LVL 1

    Accepted Solution

    Use mod_expires in your apache and set the expiry time for images to be immediate. That way your users browsers and web proxies *shouldn't* cache them and this issue goes away.

    Note though this comes with 2 warnings...
    1. Your website traffic will increase because every single image request then needs satisfying by your web server, so more server load and more bandiwidth used.
    2. Not alll proxies/ web browsers will obey the settings from mod_expires

    What I tend to do is set the expiry to be 6 hours for images, I've found it gives me a nice balance between increased traffic and shorter cached file lifetime.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now