I have a web app that makes assorted calls to load in javascript. ie:
<script src="test.js"></script>
I know the common solution to prevent caching is this:
<script src="test.js<?=$random_number?>"></script>
My challenge is that my app is not served up by a language like PHP/ASP. It is basically just a flat file. (Because we use the same source code as a PhoneGap app)
Is there a cleaner way to do a script tag other than below?
document.write("<script src='test.js?rnd=" + Math.random() + "'></script>");
use a dom script adder instead of document.write:
function addScript(u,d){(d=document).getElementsByTagName('head')[0].appendChild(d.createElement('script')).src=u}
addScript("test.js?rnd="+Math.random());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.