Best Practice to manage all asset caching (images, css, js, everything) -
i'm working on moderately-sized web application , trying come best solution make browsers use cache , invalidate when there update asset being loaded.
according research i've done here , elsewhere, seems in agreement appending ?v={version#} asset such css or js file great way automatically invalidate cache when asset updated. (as per force browser clear cache , better way prevent browser caching of javascript files)
but seems me solution should generalized assets reside on web server.
so question is, practice have build script through each src="" attribute across entire website -- whether img, css, or js, , programmatically append ?={timestamp} timestamp time when file last modified. way whenever push dev staging production, files have been modified have changed time stamp, , browser know invalidate cache files.
any flaws approach?
note: thinking on bit more, timestamp undesirable in case of changes later reverted. therefore, appending ?={md5(filecontents)} more robust approach. nevertheless, question whether implementing across assets , builds still stands.
found believe acceptable solution @ how force browser reload cached css/js files? no idea how missed in original investigation.
for comes question, note i'm referring first answer on linked page references google's mod_pagespeed plugin apache. works @ web server level, "[it works] php, rails, python, static html -- anything."
this precisely kind of solution looking for. tool, or similar, should in use web developers keep caching logic orthogonal code itself.
Comments
Post a Comment