0

I want to load js files dynamically with different names avoiding cache. Now I am doing with PHP but I can't use it in a new project.

<?php echo '<script src="lib/jquery/jquery.min.js?v='.round(microtime(true)).'"></script>';?> 
2
  • Need more details: why can't you use this in a new project? Commented Nov 10, 2021 at 20:01
  • I need to load dynamic .js files according a selected language Commented Nov 10, 2021 at 20:05

1 Answer 1

1

This works! I create the script object with HTML. Then I can dynamically assign the name and a version timestamp parameter.

<script id="myScript"></script>
<script>     
  var microTime = Date.now();   
  var myVar = "myJsFile";
  var myUrl = myVar+'.js' + '?v=' + microTime;

  myScript.src = myUrl;
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.