In the article "How we keep GitHub fast", they describe a toolbar that GitHub staff members can use to see various performance metrics of each page load. Two of the items displayed are the KB of JavaScript and CSS loaded.
How are they able to determine the KB of JavaScript and CSS loaded? Does JavaScript provide a way to access externally loaded resources?
My goal is to create a similar toolbar and display the size of all externally loaded resources.
I suppose you could search for <script>
, <link>
, <img>
, etc. tags and access their relevant src
, href
, etc. attribute, issue an XmlHttpRequest using the HEAD method, then use the Content-Length header from the response.
Another approach would be to parse the generated HTML before returning a response, determine the externally loaded resources, get their sizes directly, then append the toolbar code to the response pre-populated w/ external resource sizes.
But I'm wondering if a more efficient or simpler method is available.