title: Best Practice to manage all asset caching (images, css, js, everything)
body: <p>I'm working on a moderately-sized web application and trying to come up with the best solution to make all browsers use the cache and only invalidate it when there is an update to the asset being loaded.</p>
  
  <p>According to the research I've done here and elsewhere, everyone seems to be in agreement that appending a ?v={version#} to an asset such as a css or js file is a great way to automatically invalidate the cache when an asset is updated. (As per <a href="https://stackoverflow.com/questions/1922910/force-browser-to-clear-cache">Force browser to clear cache</a> and <a href="https://stackoverflow.com/questions/4206224/better-way-to-prevent-browser-caching-of-javascript-files">Better way to prevent browser caching of JavaScript files</a>)</p>
  
  <p>But it seems to me that this solution should be generalized to all assets that reside on a web server. </p>
  
  <p>So my question is, would it be a good practice to have a build script look through each src="" attribute across the entire website -- whether img, css, or js, and programmatically append ?={timestamp} where timestamp is the time when the file is last modified. This way whenever you push from dev to staging to production, only those files that have been modified will have a changed time stamp, and the browser will know to invalidate the cache for those files. </p>
  
  <p>Any flaws with that approach?</p>
  
  <p>NOTE: Thinking this over a bit more, timestamp would definitely be undesirable in the case of changes that are later reverted. Therefore, appending ?={md5(filecontents)} is a more robust approach. Nevertheless, the question about whether implementing this across all assets and all builds still stands.</p>