Forum Moderators: open
TWELVE POINT NINE MEGABYTES ? ! ?
There. That's out of the way. Someone had to say it. Even my picture books don't go much beyond 2MB of image files-- and those are lots of separate pictures.
#1 and most obvious. javascript is perfectly happy being split into multiple files.* You can even put (global) variables into separate files; the functions will find them just fine. Can we please assume that it isn't one behemoth of an unsplittable function?
#2 gotta be asked too. Is the entire thing based on user response, so there's absolutely no alternative to javascript? That reference to "100,000 lines of links" would make a lot of people think of databases.
* I've got one package I use locally where all the global variable declarations are in one pair of files while the actual functions are in another, much smaller pair. Before anyone starts screaming, let me stress that "locally" aspect. It runs off my hard drive.
Any chance of doing part or all of it the server, such inserting random here ?
<script type="text/javascript" src="http://www.mydomain.com/machoRandN.js"></script>
That reference to "100,000 lines of links" would make a lot of people think of databases.
if (whichSet==0) { window.open('http://forums.example.org/showthread.php?f=154&t='+ contentlinks[GetRandom(0,contentlinks.length-1)]) }
else if (whichSet==1) { window.open(trafficlinks[GetRandom(0,trafficlinks.length-1)]) }
}
My suggestion was to do it on the server using say PHP, not in the javascript.
If you can not do it on the server then try
in head section replace
<script type="text/javascript" src="http://www.mydomain.com/machoRand.js"></script>
with
<script type="text/javascript">
function insertRandomScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'machoRand' + Math.floor(Math.random()*10) + '.js'; // for 0 to 9
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
then on body tag
<body onload="insertRandomScript()">
<script type="text/javascript">
function insertRandomScript() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'home/someting/domain/machoRand' + Math.floor(Math.random()*48) + '.js'; // for 0 to 47
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
i tried adding a full path but no luck:
script.src = 'home/someting/domain/machoRand
'http://www.mydomain.com/home/someting/domain/machoRand'
Backtracking a little bit: If I've understood it right, the code starts executing in response to user action. But at that point it pulls up something at random; the user isn't asking for one of those 100,000 URLs by name. If so, it seems like the random numbers could perfectly well be generated ahead of time, when the page is built, and kept in some type of holding bin. The user doesn't know, and doesn't need to know, that the numbers were really generated several seconds before he clicked. Store some reasonable number of them-- ten or a hundred or whatever is appropriate to the page-- and refresh the page if you run out.