chrome.loadTimes()
एक नॉन-स्टैंडर्ड एपीआई है, जो डेवलपर को लोडिंग मेट्रिक और नेटवर्क की जानकारी दिखाता है. इससे डेवलपर को, असल दुनिया में अपनी साइट की परफ़ॉर्मेंस को बेहतर तरीके से समझने में मदद मिलती है.
इस एपीआई को 2009 में लागू किया गया था. इसलिए, इसके ज़रिए रिपोर्ट की जाने वाली सभी उपयोगी जानकारी, स्टैंडर्ड एपीआई में मिल सकती है, जैसे:
- नेविगेशन समय 2
- पेंट टाइमिंग
nextHopProtocol
नेविगेशन टाइमिंग 2 और संसाधन समय 2 में जोड़ा गया.
इन स्टैंडर्ड एपीआई को कई ब्राउज़र वेंडर लागू कर रहे हैं. इस वजह से, Chrome 64 में chrome.loadTimes()
को बंद कर दिया गया है.
काम न करने वाला एपीआई
chrome.loadTimes()
फ़ंक्शन एक ही ऑब्जेक्ट दिखाता है, जिसमें उसकी लोडिंग और नेटवर्क की सारी जानकारी होती है. उदाहरण के लिए, नीचे दिया गया ऑब्जेक्ट, www.google.com पर chrome.loadTimes()
को कॉल करने का नतीजा है:
{
"requestTime": 1513186741.847,
"startLoadTime": 1513186741.847,
"commitLoadTime": 1513186742.637,
"finishDocumentLoadTime": 1513186742.842,
"finishLoadTime": 1513186743.582,
"firstPaintTime": 1513186742.829,
"firstPaintAfterLoadTime": 0,
"navigationType": "Reload",
"wasFetchedViaSpdy": true,
"wasNpnNegotiated": true,
"npnNegotiatedProtocol": "h2",
"wasAlternateProtocolAvailable": false,
"connectionInfo": "h2"
}
स्टैंडर्डाइज़्ड रीप्लेसमेंट
अब स्टैंडर्ड एपीआई का इस्तेमाल करके, ऊपर बताई गई हर वैल्यू देखी जा सकती है. नीचे दी गई टेबल में, हर वैल्यू को उसके स्टैंडर्ड एपीआई से मैच किया जाता है. नीचे दिए गए सेक्शन में, पुराने एपीआई में हर वैल्यू को मॉडर्न वैल्यू के साथ पाने के तरीके के कोड के उदाहरण दिखाए गए हैं.
chrome.loadTimes() सुविधा
| एपीआई को मानक तरीके से बदलना |
---|---|
requestTime |
नेविगेशन का दूसरा समय |
startLoadTime |
नेविगेशन का दूसरा समय |
commitLoadTime |
नेविगेशन का दूसरा समय |
finishDocumentLoadTime |
नेविगेशन का दूसरा समय |
finishLoadTime |
नेविगेशन का दूसरा समय |
firstPaintTime |
पेंट करने का समय |
firstPaintAfterLoadTime |
लागू नहीं |
navigationType |
नेविगेशन का दूसरा समय |
wasFetchedViaSpdy |
नेविगेशन का दूसरा समय |
wasNpnNegotiated |
नेविगेशन का दूसरा समय |
npnNegotiatedProtocol |
नेविगेशन का दूसरा समय |
wasAlternateProtocolAvailable |
लागू नहीं |
connectionInfo |
नेविगेशन का दूसरा समय |
नीचे दिए गए कोड के उदाहरण में, chrome.loadTimes()
से दिखाए गए कोड के बराबर वैल्यू दी गई हैं. हालांकि, नए कोड के लिए, इन कोड उदाहरणों का सुझाव नहीं दिया जाता. इसकी वजह यह है कि chrome.loadTimes()
, सेकंड में epoch टाइम में समय की वैल्यू देता है. वहीं, नए परफ़ॉर्मेंस एपीआई आम तौर पर पेज के समय की शुरुआत के हिसाब से मिलीसेकंड में वैल्यू रिपोर्ट करते हैं जो परफ़ॉर्मेंस का विश्लेषण करने के लिए ज़्यादा काम के होते हैं.
कई उदाहरण परफ़ॉर्मेंस टाइमलाइन 2 एपीआई (उदाहरण के लिए,
performance.getEntriesByType()
) के सुझाव भी देते हैं. हालांकि, ये पुराने
नेविगेशन समय 1 एपीआई के लिए फ़ॉलबैक उपलब्ध कराते हैं, क्योंकि इसमें
ज़्यादा ब्राउज़र काम करता है. आने वाले समय में, परफ़ॉर्मेंस टाइमलाइन एपीआई को प्राथमिकता दी जाएगी.
आम तौर पर, इन्हें ज़्यादा सटीक तरीके से रिपोर्ट किया जाता है.
requestTime
function requestTime() {
// If the browser supports the Navigation Timing 2 and HR Time APIs, use
// them, otherwise fall back to the Navigation Timing 1 API.
if (window.PerformanceNavigationTiming && performance.timeOrigin) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return (ntEntry.startTime + performance.timeOrigin) / 1000;
} else {
return performance.timing.navigationStart / 1000;
}
}
startLoadTime
function startLoadTime() {
// If the browser supports the Navigation Timing 2 and HR Time APIs, use
// them, otherwise fall back to the Navigation Timing 1 API.
if (window.PerformanceNavigationTiming && performance.timeOrigin) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return (ntEntry.startTime + performance.timeOrigin) / 1000;
} else {
return performance.timing.navigationStart / 1000;
}
}
commitLoadTime
function commitLoadTime() {
// If the browser supports the Navigation Timing 2 and HR Time APIs, use
// them, otherwise fall back to the Navigation Timing 1 API.
if (window.PerformanceNavigationTiming && performance.timeOrigin) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return (ntEntry.responseStart + performance.timeOrigin) / 1000;
} else {
return performance.timing.responseStart / 1000;
}
}
finishDocumentLoadTime
function finishDocumentLoadTime() {
// If the browser supports the Navigation Timing 2 and HR Time APIs, use
// them, otherwise fall back to the Navigation Timing 1 API.
if (window.PerformanceNavigationTiming && performance.timeOrigin) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return (ntEntry.domContentLoadedEventEnd + performance.timeOrigin) / 1000;
} else {
return performance.timing.domContentLoadedEventEnd / 1000;
}
}
finishLoadTime
function finishLoadTime() {
// If the browser supports the Navigation Timing 2 and HR Time APIs, use
// them, otherwise fall back to the Navigation Timing 1 API.
if (window.PerformanceNavigationTiming && performance.timeOrigin) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return (ntEntry.loadEventEnd + performance.timeOrigin) / 1000;
} else {
return performance.timing.loadEventEnd / 1000;
}
}
firstPaintTime
function firstPaintTime() {
if (window.PerformancePaintTiming) {
const fpEntry = performance.getEntriesByType('paint')[0];
return (fpEntry.startTime + performance.timeOrigin) / 1000;
}
}
firstPaintAfterLoadTime
function firstPaintTimeAfterLoad() {
// This was never actually implemented and always returns 0.
return 0;
}
navigationType
function navigationType() {
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ntEntry.type;
}
}
wasFetchedViaSpdy
function wasFetchedViaSpdy() {
// SPDY is deprecated in favor of HTTP/2, but this implementation returns
// true for HTTP/2 or HTTP2+QUIC/39 as well.
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ['h2', 'hq'].includes(ntEntry.nextHopProtocol);
}
}
wasNpnNegotiated
function wasNpnNegotiated() {
// NPN is deprecated in favor of ALPN, but this implementation returns true
// for HTTP/2 or HTTP2+QUIC/39 requests negotiated via ALPN.
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ['h2', 'hq'].includes(ntEntry.nextHopProtocol);
}
}
npnNegotiatedProtocol
function npnNegotiatedProtocol() {
// NPN is deprecated in favor of ALPN, but this implementation returns the
// HTTP/2 or HTTP2+QUIC/39 requests negotiated via ALPN.
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ['h2', 'hq'].includes(ntEntry.nextHopProtocol) ?
ntEntry.nextHopProtocol : 'unknown';
}
}
wasAlternateProtocolAvailable
function wasAlternateProtocolAvailable() {
// The Alternate-Protocol header is deprecated in favor of Alt-Svc
// (https://www.mnot.net/blog/2016/03/09/alt-svc), so technically this
// should always return false.
return false;
}
connectionInfo
function connectionInfo() {
if (window.PerformanceNavigationTiming) {
const ntEntry = performance.getEntriesByType('navigation')[0];
return ntEntry.nextHopProtocol;
}
}
कॉन्टेंट हटाने का प्लान
Chrome 64 में chrome.loadTimes()
API के इस्तेमाल पर रोक लगा दी जाएगी और इसे 2018 के आखिर में हटा दिया जाएगा. डेटा के नुकसान से बचने के लिए, डेवलपर को जल्द से जल्द अपना कोड माइग्रेट कर लेना चाहिए.
रोक लगाने का इरादा | Chromestatus Tracker | Chromium गड़बड़ी