最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

metadata - how to get lengthsize of a webpage using javascript - Stack Overflow

programmeradmin2浏览0评论

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 ?

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 ?

Share Improve this question asked Oct 26, 2015 at 17:32 anjanbanjanb 14k19 gold badges80 silver badges106 bronze badges 3
  • possibly already answered here: stackoverflow./questions/890221/… – GrafiCode Commented Oct 26, 2015 at 17:35
  • Looking for a plain javascript(without additional libraries) answer. thank you. – anjanb Commented Oct 27, 2015 at 5:20
  • @ GrafiCode Studio : thanks. User Stev on that question answered my question. – anjanb Commented Oct 27, 2015 at 6:16
Add a ment  | 

4 Answers 4

Reset to default 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;

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

Are you looking for the height of the browser window?

window.innerHeight;
window.innerWidth;

Here you go:

Math.ceil($('html').html().length / 1024) + "KB";
发布评论

评论列表(0)

  1. 暂无评论