Options
All
  • Public
  • Public/Protected
  • All
Menu

resource-loader-inspector

Index

Variables

Const addXhrContentLength

addXhrContentLength: LoaderMiddleware = <LoaderMiddleware>function addXhrContentLength(this: Loader,resource: Resource,next: Function): void {if (!this.xhr) {next();return;}const contentLength = this.xhr.getResponseHeader('Content-Length');// getResponseHeader may return nullif (!contentLength) {next();return;}const contentLengthInt = parseInt(contentLength, 10);if (resource.inspector) {if (resource.inspector.alreadyLoaded) {next();return;}resource.inspector.contentLength = contentLengthInt;}if (this.inspector) {this.inspector.summary.totalContentLength += contentLengthInt;}next();}

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.

Const incrementResourceCount

incrementResourceCount: LoaderMiddleware = <LoaderMiddleware>function incrementResourceCount(this: Loader,resource: Resource,next: Function): void {if (resource.inspector && resource.inspector.alreadyLoaded) {next();return;}if (this.inspector) {this.inspector.summary.resourceCount++;}next();}

Increments resource count.

Const markLoaded

markLoaded: LoaderMiddleware = <LoaderMiddleware>function markLoaded(this: Loader,resource: Resource,next: Function): void {if (resource.inspector) {resource.inspector.alreadyLoaded = !!resource.data;}next();}

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.

Const setInspectorProperty

setInspectorProperty: LoaderMiddleware = <LoaderMiddleware>function setInspectorProperty(this: Loader,resource: Resource,next: Function): void {resource.inspector = {contentLength: 0,alreadyLoaded: false};next();}

Set default inspector property to proceed rest of middlewares.

Generated using TypeDoc