我怎样才能得到一个网站的加载时间和音量? [英] How can I get the loading time and volume of a website?

查看:90
本文介绍了我怎样才能得到一个网站的加载时间和音量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作是应该测量加载时间和网站的数量,我给作为输入的程序。

I'm working on a program that should measure loading time and volume of a website that I give as an input.

在这里,我有一些code返回网站只是响应时间,但我想总加载时间和项目的总容积,例如(图片,JavaScript的,HTML,等等)。

Here I have some code that returns just response time of website but I want the total loading time and total volume of items such (pictures, JavaScript, HTML, etc.).

public string Loading_Time(string url)
{
    Stopwatch stopwatch = new Stopwatch();

    WebClient client = new WebClient();
    client.Credentials = CredentialCache.DefaultCredentials;

    stopwatch.Start();
    string result = client.DownloadString(url);
    stopwatch.Stop();

    return stopwatch.Elapsed.Milliseconds.ToString();
}

我怎样才能做到这一点?

How can I achieve that?

推荐答案

这将是一个有点艰难。通过使用类似的开始 HTMLAgilityPack 或类似从您的原始请求解析返回的HTML的东西(不要试图解析HTML自己!)

This is going to be a little bit tough. Start by using something like HTMLAgilityPack or something similar to parse the returned html from your original request (dont try to parse HTML yourself!)

通过一次解析的HTML对象重新presentation扫描,并决定要测量的大小的东西。通常,这将是

Scan through the object representation of the HTML once parsed, and decide what you want to measure the size of. Typically this will be


  • 包括,如CSS或JavaScript

  • 在IMG
  • 图片和按钮元素,以及背景图片

困难的是,通常的图像被指定为CSS样式表的一部分 - 所以你要尝试解析每一个CSS文件也获得这些

The difficulty is that often images are specified as part of a css stylesheet - so are you going to try to parse every css file to obtain these too?

您对您可能获得的下载字符串的字节大小的HTML,原来的要求。开始与该号码作为你的卷。

The original request you made for the HTML you could have obtained the byte size of the downloaded string. Start with this number as your "volume".

现在作出对每个JS,CSS,图像等文件以相同的方式单独的请求。但是,所有你感兴趣的是,每次下载的字节大小 - 它随时可用,当你做出一个HTTP请求。每个项目的字节大小添加到总量。

Now make a separate request for each js, css, image etc file in the same way. But all you're interested in is the byte size of each download - its readily available when you make an HTTP request. Add each item's byte size to the total.

当你完成,你将拥有该网页的所有工件的总字节数。

When you're finished you will have the total byte size for all artifacts of that web page.

这篇关于我怎样才能得到一个网站的加载时间和音量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆