gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:37:52 25 4
gpt4 key购买 nike

我想知道,由于现代浏览器中的window.performance对象中有domainLookupStart和domainLookupEnd属性,有没有办法知道第三方站点上托管的脚本的域查找时间?或者这个时间已经包含在给定的domainLookupStart和domainLookupEnd中?

最佳答案

您可以使用Resource Timing API .

记录当前文档中所有资源的 DNS 查找时间:

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

要获取单个命名资源的所有统计信息:

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

结果示例:

[
{
"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"
}
]

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

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

关于javascript - 获取跨域脚本标签的 HTML5 性能对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26408074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com