Other than caching every hour, or every week, you may cache according to file data.
<script src="js/my_script.js?v=<?=md5_file('js/my_script.js')?>"></script>
or use file modification time:
<script src="js/my_script.js?v=<?=filemtime('js/my_script.js')?>"></script>
or use file modification every hour:
<script type="text/javascript" src="js/myscript.js?v=<?php echo date('YmdHis'); ?>"></script>
or Using Javascript
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; } } } }
To get host url of current server simply replace application\config\config.php [crayon-679fd56e0bb13868187682/] with [crayon-679fd56e0bb1d574159534/]
You should first test the existence of a file by file_exists(). [crayon-679fd56e0bcc6908383259/] or simple solution…
[crayon-679fd56e0bd9f842527931/] Output the random string with the call below: [crayon-679fd56e0bda3002741340/]
Note: from WordPress Use it like this: [crayon-679fd56e0be4d491732773/] Code: [crayon-679fd56e0be50942799465/]
[crayon-679fd56e0bfa6245135501/] or [crayon-679fd56e0bfa9831305934/]