Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1043993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:45:24+00:00 2026-05-16T15:45:24+00:00

If I understand correctly, a broswer caches images, JS files, etc. based on the

  • 0

If I understand correctly, a broswer caches images, JS files, etc. based on the file name. So there’s a danger that if one such file is updated (on the server), the browser will use the cached copy instead.

A workaround for this problem is to rename all files (as part of the build), such that the file name includes an MD5 hash of it’s contents, e.g.

foo.js -> foo_AS577688BC87654.js
me.png -> me_32126A88BC3456BB.png

However, in addition to renaming the files themselves, all references to these files must be changed. For exmaple a tag such as <img src="me.png"/> should be changed to <img src="me_32126A88BC3456BB.png"/>.

Obviously this can get pretty complicated, particularly when you consider that references to these files may be dynamically created within server-side code.

Of course, one solution is to completely disable caching on the browser (and any caches between the server and the browser) using HTTP headers. However, having no caching will create it’s own set of problems.

Is there a better solution?

Thanks,
Don

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:45:24+00:00Added an answer on May 16, 2026 at 3:45 pm

    The best solution seems to be to version filenames by appending the last-modified time.

    You can do it this way: add a rewrite rule to your Apache configuration, like so:

    RewriteRule ^(.+)\.(.+)\.(js|css|jpg|png|gif)$ $1.$3
    

    This will redirect any “versioned” URL to the “normal” one. The idea is to keep your filenames the same, but to benefit from cache. The solution to append a parameter to the URL will not be optimal with some proxies that don’t cache URLs with parameters.

    Then, instead of writing:

    <img src="image.png" />
    

    Just call a PHP function:

    <img src="<?php versionFile('image.png'); ?>" />
    

    With versionFile() looking like this:

    function versionFile($file){
        $path = pathinfo($file);
        $ver = '.'.filemtime($_SERVER['DOCUMENT_ROOT'].$file).'.';
        echo $path['dirname'].'/'.str_replace('.', $ver, $path['basename']);
    }
    

    And that’s it! The browser will ask for image.123456789.png, Apache will redirect this to image.png, so you will benefit from cache in all cases and won’t have any out-of-date issue, while not having to bother with filename versioning.

    You can see a detailed explanation of this technique here: http://particletree.com/notebook/automatically-version-your-css-and-javascript-files/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Do I understand correctly that CCLabelBMFont only loads the font texture once, no matter
If I understand it correctly this means extern void foo(); that the function foo
If I understand correctly, ClickOnce only checks for prerequisites with the first install of
If I understand correctly the .net runtime will always clean up after me. So
If I understand correctly, in .NET the default implementation of Object.GetHashCode() returns a value
This is just a quick question to understand correctly what happens when you create
If I understand this correctly: Current CPU developing companies like AMD and Intel have
If I understand this correctly, the program counter points to the address of the
Been trying my best to understand this correctly. What is the difference between an
I've just read up on Thread.IsBackground and if I understand it correctly, when it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.