简体   繁体   English

获取跨域脚本标签的HTML5性能对象

[英]Get HTML5 performance object for cross-domain script tag

I'm wondering, as there are domainLookupStart and domainLookupEnd attributes in the window.performance object in modern browsers, is there any way to know the domain lookup time of scripts that are hosted on third-party sites ? 我想知道,由于现代浏览器的window.performance对象中存在domainLookupStart和domainLookupEnd属性,有没有办法知道托管在第三方站点上的脚本的域查找时间? or is this time already included in the given domainLookupStart and domainLookupEnd ? 还是这次已经包含在给定的domainLookupStart和domainLookupEnd中?

You can use the Resource Timing API . 您可以使用Resource Timing API

To log the DNS lookup time for all resources in the current document: 要记录当前文档中所有资源的DNS查找时间:

var resourceTimings = performance.getEntriesByType('resource');
  resourceTimings.forEach(function(resource) {
  console.log(resource.name + ' ' + (resource.domainLookupEnd - resource.domainLookupStart));
})

To get all stats for a single named resource: 要获取单个命名资源的所有统计信息:

var jQueryTiming = performance.getEntriesByName("http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js")

Example result: 结果示例:

[
  {
    "responseEnd": 436.0980000055861,
    "responseStart": 434.55200002063066,
    "requestStart": 332.36200001556426,
    "secureConnectionStart": 0,
    "connectEnd": 332.30700000422075,
    "connectStart": 332.18300002045,
    "domainLookupEnd": 332.18300002045,
    "domainLookupStart": 320.040999999037,
    "fetchStart": 316.93600001744926,
    "redirectEnd": 0,
    "redirectStart": 0,
    "initiatorType": "script",
    "duration": 119.16199998813681,
    "startTime": 316.93600001744926,
    "entryType": "resource",
    "name": "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"
  }
]

Recommended reading: http://www.sitepoint.com/introduction-resource-timing-api/ 推荐阅读: http : //www.sitepoint.com/introduction-resource-timing-api/

Current browser compatibility: http://caniuse.com/#feat=resource-timing 当前浏览器的兼容性: http : //caniuse.com/#feat=resource-timing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM