Other than caching every hour, or every week, you may cache according to file data.
1 |
<script src="js/my_script.js?v=<?=md5_file('js/my_script.js')?>"></script> |
or use file modification time:
1 |
<script src="js/my_script.js?v=<?=filemtime('js/my_script.js')?>"></script> |
or use file modification every hour:
1 |
<script type="text/javascript" src="js/myscript.js?v=<?php echo date('YmdHis'); ?>"></script> |
or Using Javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function reloadScripts(toRefreshList/* list of js to be refresh */, key /* change this key every time you want force a refresh */) { var scripts = document.getElementsByTagName('script'); for(var i = 0; i < scripts.length; i++) { var aScript = scripts[i]; for(var j = 0; j < toRefreshList.length; j++) { var toRefresh = toRefreshList[j]; if(aScript.src && (aScript.src.indexOf(toRefresh) > -1)) { new_src = aScript.src.replace(toRefresh, toRefresh + '?k=' + key); // console.log('Force refresh on cached script files. From: ' + aScript.src + ' to ' + new_src) aScript.src = new_src; } } } } |