4

We get the webpage timing info using w3c navigation API.
we get the resource information using the resource timing API.
Now, how to get the size of the webpage. It appears that if I know when the page loaded, etc, I should know when the last byte was downloaded -- this should be enough to give me the length/size of the page.

How do I get this length/size ?

anjanb
  • 12,999
  • 18
  • 77
  • 106

4 Answers4

4

Found the answer at : How to get current page size in KB using just javascript?. User @Stev has answered it

document.getElementsByTagName('HTML')[0].outerHTML.length;
Community
  • 1
  • 1
anjanb
  • 12,999
  • 18
  • 77
  • 106
1

Since HTML files are pretty much just text files, you could count how many characters you have and that would be your web page size in bytes, assuming you have 1 character = 1 byte. Then, divide by a multiple of 1024 to get KB, MB, GB etc.

$("html").html().length / (n * 1024)

Edit with javascript only :

Shortcut to retrieve the root element of the document source

document.documentElement.outerHTML.length

or

Retrieve the array of elements who's tag name is "html", assuming the first one is your root element (true for all valid HTML files), and count length :

document.getElementsByTagName("html")[0].outerHTML.length

John Pink
  • 607
  • 5
  • 14
0

Are you looking for the height of the browser window?

window.innerHeight;
window.innerWidth;
Alek Hurst
  • 4,527
  • 5
  • 19
  • 24
  • I was looking for the size of the html page in Kilobytes/MB. This is the size of the webpage on file if I were to save the webpage to the disk. – anjanb Oct 27 '15 at 05:21
0

Here you go:

Math.ceil($('html').html().length / 1024) + "KB";
Lucas Rodrigues
  • 1,234
  • 2
  • 11
  • 22