How can you get the actual file size(not in pixels,in bytes) of the document a js script is running on? The solution should work in all major browsers.
//
function hrefSize(){
try{
var O= new XMLHttpRequest;
O.open("HEAD", document.URL, false);
O.send(null);
if(O.status== 200){
return O.getResponseHeader('Content-Length');
}
else return 0;
}
catch(er){
return 0;
}
}
alert(hrefSize()+' bytes');
You could propably refetch the page via ajax and get the length of it as a string, but this will be suboptimal because it will trigger another HTTP request and have to wait for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With