Retrieve content length from xhr and store the value
to resource and loader.inspectorSummary
This middleware only works for loader that have valid xhr property.
Mark resource with loaded status.
Usually duplicate resource loading is guarded by resource-loader itself.
TODO: consider remove this and let users have responsibility for custom loader.
Const requestResourceSize
requestResourceSize:LoaderMiddleware = <LoaderMiddleware>function requestResourceSize(this: Loader,resource: Resource,next: Function): void {if (resource.inspector && resource.inspector.alreadyLoaded) {next();return;}if (this.xhr) {return;}const xhr = new XMLHttpRequest();xhr.open('HEAD', resource.url, true);xhr.addEventListener('load',() => {const contentLength = xhr.getResponseHeader('Content-Length');// getResponseHeader may return nullif (!contentLength) {return;}const contentLengthInt = parseInt(contentLength, 10);if (resource.inspector) {resource.inspector.contentLength = contentLengthInt;}if (this.inspector) {this.inspector.summary.totalContentLength += contentLengthInt;}},false);xhr.send();// no need to wait xhr procedurenext();}
Requests resource size using HEAD method for resources not retrieved via XHR.
Retrieve content length from xhr and store the value to resource and loader.inspectorSummary
This middleware only works for loader that have valid xhr property.