Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Calling a .js that is 12.9mb


Fess - 5:27 am on Dec 29, 2012 (gmt 0)


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()">


LifeinAsia, rainborick, thanks for responding, I agree that the load time is impractical.

dave, thank you very much. That worked after cutting the script into 48 parts (300kb each) ;O) so its a random of 0-47.
Just a additonal question:

How would I call the script from another part of the server, i tried adding a full path but no luck:

script.src = 'home/someting/domain/machoRand' + Math.floor(Math.random()*48) + '.js';



<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>



greatful..
~Fess


Thread source:: http://www.webmasterworld.com/javascript/4531247.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com