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 |
नेविगेशन समय 2 |
startLoadTime |
नेविगेशन समय 2 |
commitLoadTime |
नेविगेशन समय 2 |
finishDocumentLoadTime |
नेविगेशन समय 2 |
finishLoadTime |
नेविगेशन समय 2 |
firstPaintTime |
पेंट करने का समय |
firstPaintAfterLoadTime |
लागू नहीं |
navigationType |
नेविगेशन समय 2 |
wasFetchedViaSpdy |
नेविगेशन समय 2 |
wasNpnNegotiated |
नेविगेशन समय 2 |
npnNegotiatedProtocol |
नेविगेशन समय 2 |
wasAlternateProtocolAvailable |
लागू नहीं |
connectionInfo |
नेविगेशन समय 2 |
नीचे दिए गए कोड उदाहरण,
chrome.loadTimes()
. हालांकि, नए कोड के लिए ये कोड उदाहरण
सुझाया गया. इसकी वजह यह है कि chrome.loadTimes()
, epoch टाइम की वैल्यू सेकंड में देता है, जबकि नए परफ़ॉर्मेंस एपीआई
आम तौर पर, किसी पेज की
समय का ऑरिजिन, जो आम तौर पर
ये परफ़ॉर्मेंस के विश्लेषण के लिए ज़्यादा मददगार होती हैं.
उनमें से कई उदाहरणों में परफ़ॉर्मेंस टाइमलाइन 2 वाले एपीआई भी शामिल हैं (जैसे,
performance.getEntriesByType()
) लेकिन पुराने वर्शन के लिए फ़ॉलबैक दें
नेविगेशन समय 1 API जैसा यह है
बड़ी ब्राउज़र सुविधा का इस्तेमाल किया जा सकता है. आगे से, परफ़ॉर्मेंस टाइमलाइन एपीआई को प्राथमिकता दी जाएगी
और आम तौर पर इन्हें ज़्यादा सटीक तरीके से रिपोर्ट किया जाता है.
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()
एपीआई के इस्तेमाल पर रोक लगा दी जाएगी. इसे टारगेट किया गया है
2018 के आखिर में हटा दिया गया. डेवलपर को अपने कोड को जल्द से जल्द माइग्रेट कर लेना चाहिए
ताकि डेटा को किसी भी तरह के नुकसान से बचाया जा सके.
इस्तेमाल बंद करने की इच्छा | Chromestatus ट्रैकर | Chromium बग