how to determine filesize of all object ((images, css, objects and scripts)) defined inside a html page
Is there way to dete开发者_如何学JAVArmine filesize of html file forexample i have a url
http://url/item/id/1
can i determine the size of files when this url is loaded
I want to show in page 256 Kb loaded in 0.268 seconds at the end of page
try updates
on localhost/testing/index.php
echo filesize("http://localhost/testing/testing.html");
on localhost/testing/testing.html
<html>
<head>
</head>
<body>
<img src="test.jpg"/>
</body>
</htm>
on apache error.log
[Fri Dec 31 14:46:05 2010] [error] [client ::1] PHP Warning: filesize(): stat
failed for http://localhost/testing/testing.html in /var/www/testing/index.php
on line 4
on index.php if i do
echo filesize("/var/www/testing/testing.html");
then i get 80 bytes that is without any image
You might want to hold your page render in a buffer (using ob_start()) and then parse it prior to flushing the buffer:
1) You'll want to save the buffer contents prior to rendering using ob_get_contents() (obviously this won't work if you haven't triggered the output buffer using ob_start()) (just to avoid having to call ob_get_contents() multiple times).
2) Check the size of the buffer using strlen($varname), unless you're using mbchar types (unicode) in your HTML, then you'll have to look at alternate methods.
3) Then, parse the buffer for any external CSS files or img tags (should be do'able with a single regex search).
4) Iterate through the list of external CSS files and img tags and get their individual file sizes.
5) Add the CSS and img file sizes to the buffer size and there you go. Total file size.
(Note that anything else that incurs an HTTP request would also have to be calculated)
Simply getting filesize for testing.html won't give you all the data you're looking for (unfortunately), as it only calculates the size of the given file; not any of its contents.
I'd be willing to bet that there's already something out there floating on the OS wagon somewhere that would do most (if not all) of this for you.
精彩评论