how to load script dynamically with versioning

how to load script dynamically with versioning
 In this article, we are going to see , how to load script dynamically with versioning

var script = document.createElement("script");  
script.src = `https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js?v=${(new Date()).getTime()}`; //you can put your local script also
script.onload=callback;
document.body.appendChild(script);

//or you can create function

function addScript (src) {
  var script = document.createElement("script");
  script.src = `${src}?v=${(new Date()).getTime()}` //here is src dynamic versioning
  script.onload=callback;
  document.body.appendChild(script);
  return script;
}

Post a Comment

0 Comments