Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  146] [ 2]  / answers: 1 / hits: 16213  / 12 Years ago, fri, february 15, 2013, 12:00:00

I want to load an external javascript file into the page and make sure its not cached. I do not have access to php so I cant generate a random string after the filename.



In PHP the script would look like this:



<script src=http://site.com/cool.js?<?php echo $randomnumber; ?>></script>


Is there a way to do something like that using only javascript?


More From » jquery

 Answers
149

Use jQuery's getScript instead of a script tag.



$.getScript(http://example.com/cool.js);


or pure JavaScript



var scr = document.createElement(script);
scr.src = http://example.com/cool.js + ?ts= + new Date().getTime();
document.getElementsByTagName(head)[0].appendChild(scr);

[#80204] Thursday, February 14, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
addie

Total Points: 699
Total Questions: 89
Total Answers: 97

Location: Cayman Islands
Member since Fri, Mar 4, 2022
2 Years ago
;