SV: [thelist] Recieved number of bytes

Andreas Wahlin Andreas.Wahlin at ufl.gu.se
Tue Jun 22 08:36:00 CDT 2004


The script sure worked, in IE only though (well, rather, it did NOT work
in Firefox 0.9)
I have a pretty good idea about how the script works, but some parts
seem overy complicated, though I have what I wanted so I don't know if
I'll need to clean it up, but I did clean up the structure some

function weigh() {
	var fs = 0, f = 1, p = new String();
	for (var i = 0; i < document.images.length; i++) {
		if (p.indexOf('('+document.images[i].src+')')<0)
			fs += parseInt(document.images[i].fileSize);
		p += '('+document.images[i].src+')';
	}
	fs += parseInt(document.fileSize);
	fs += '';
	for(i = fs.length-1; i > 0; i--) {
		if (f/3 == Math.ceil(f/3))
			fs = fs.substring(0, i) + ',' + fs.substring(i,
fs.length);
		f++;
	}
	alert('This page weighs '+fs+' bytes.');
}


The last fore statement is easy, that's for adding , so as to format the
weigh string a bit better, purely cosmetic. What I'm concered about is
the way pictures are fetched ... What are the '(' for? Isn't it easier
to just check if the source exists? And if it's in the document.images
array, why bother at all since it's an image?

Oh, I also changed the document.image() to document.image[], as it
should be in array accessing.

Thanks a lot for the script, I got exactly what I wanted!

Andreas


More information about the thelist mailing list