If a URL points to a page that contains images, html, javascripts, pdf file ...
How to determine how many requests it makes to get all those parts ? And the size of each part ?
My code looks like this :
try
{
url=new URL(aUrl);
connection=(HttpURLConnection)url.openConnection();
connection.setRequestMethod("HEAD");
// connection.connect();
size=connection.getContentLengthLong();
Out("URL : "+aUrl);
if (size<0) Out("Could not determine file size.");
else Out("Size : " + size+" bytes");
connection.getInputStream().close();
}
catch (Exception e) { e.printStackTrace(); }
It onlys gets the size specified by the HEAD in the URL, I guess that's the total size, how can I figure out the size of each part : html, javascript, images... ?
And more importantly, how many requests ?
There is no easy way to get this information apart from fetching everything. The top level HTML document you get with the first request contains links to other documents (images, style sheets, Javascript, ...) which in turn could contain further links (e.g. a background image referenced from a style sheet). These other resources may even reside on other servers.
To make things even more complicated, the Javascript in the page may load further resources dynamically.