I have used 5 JavaScript compressors to compress a JavaScript library (JSMin, YUI compressor, Packer, closure compiler and UglifyJS)
Now I know that closure compiler is the winner in reducing the filesize. However, I also want to test out the performance gains. What would be a good way to do this?
I made a simple test page that uses all the library's public methods. Is there a tool for testing out the page speed of this test page? Eg. running it X times on a browser and return the average loading speed.
Thanks for your answers!
There's no need to be complex about it:
<html>
<head>
<script>
var time = new Date();
</script>
<script src="..."></script>
... more scripts ...
</head>
<body>
<script>
document.write("Time: " + String((new Date() - time)/1000) + " seconds");
</script>
</body>
</html>
Scripts in the <head>
generally load serially, so this should be a reasonable method for measuring script execution time. If you have scripts executing form <body onload="...">
, then do the time elapsed calculation at the end of that function instead of the end of the body.
This method would not measure execution time for "asynchronous" functions executed via setTimeout
or setInterval
, but those shouldn't count against load time.
An alternative and likely simpler option is to use the javascript profiler built-in to Chrome or Safari's web inspector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With