Last active
November 9, 2019 04:23
-
-
Save zhiqiang21/60317bcc198a703e1c158b6e851ec524 to your computer and use it in GitHub Desktop.
获取网络请求各个阶段的信息
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { urlQuery } from './url'; | |
(function(){ | |
const entryList = performance && performance.getEntries && performance.getEntries(); | |
const country = urlQuery.location_country; | |
const cityid = urlQuery.location_cityid; | |
let linkPerformance = null; | |
console.log(`entryList`, entryList); | |
if (!Array.isArray(entryList)) return; | |
// 一般情况下我们都会将css放在head标签中,js放在body标签底部。如果静态文件使用了单独的CDN域名这是只需要获取第一个加载的CSS的对象就行 | |
for (let i = 0; i < entryList.length; i++) { | |
const obj = entryList[i]; | |
if (obj.initiatorType === 'link') { | |
linkPerformance = obj; | |
break; | |
} | |
} | |
console.log(`linkPerformance`, linkPerformance); | |
const cssDomainlookStart = linkPerformance ? linkPerformance.domainLookupStart : 0; | |
const cssDomainlookEnd = linkPerformance ? linkPerformance.domainLookupEnd : 0; | |
const connectStart = linkPerformance ? linkPerformance.connectStart : 0; | |
const connectEnd = linkPerformance ? linkPerformance.connectEnd : 0; | |
const requestStart = linkPerformance ? linkPerformance.requestStart : 0; | |
const responseStart = linkPerformance ? linkPerformance.responseStart : 0; | |
const responseEnd = linkPerformance ? linkPerformance.responseEnd : 0; | |
Omega && Omega.trackEvent && Omega.trackEvent('static_domain_timing', '', { | |
country: country, | |
lookupTiming: cssDomainlookEnd - cssDomainlookStart, | |
connectTiming: connectEnd - connectStart, | |
requestTiming: responseStart - requestStart, | |
responseTiming: responseEnd - responseStart, | |
host: 'static.didiglobal.com', | |
cityid | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment