Skip to content

Instantly share code, notes, and snippets.

@kasparsb
Created July 5, 2018 12:02
Show Gist options
  • Save kasparsb/1c08488db862e092278a2b405f49e1f0 to your computer and use it in GitHub Desktop.
Save kasparsb/1c08488db862e092278a2b405f49e1f0 to your computer and use it in GitHub Desktop.
Javascript for dynamic script and css loading with cache buster
<script>
(function(d){
var s = d.createElement('link');
d.getElementsByTagName('head')[0].appendChild(s);
s.setAttribute('type', 'text/css');
s.setAttribute('rel', 'stylesheet');
s.setAttribute('href', 'app.css?v='+(new Date()).getTime());
var s = d.createElement('script');
d.getElementsByTagName('head')[0].appendChild(s);
s.src = 'app.js?v='+(new Date()).getTime();
s.onload = function(){
nowScriptIsReady()
}
s.onreadystatechange= function () {
if (this.readyState == 'complete') {
nowScriptIsReady()
}
}
})(document)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment