chrome.loadTimes()
هي واجهة برمجة تطبيقات غير عادية تعرض مقاييس التحميل
ومعلومات الشبكة للمطورين بهدف مساعدتهم على فهم
أداء موقعك على أرض الواقع.
وحيث إن واجهة برمجة التطبيقات هذه قد تم تطبيقها في عام 2009، يمكن الحصول على جميع المعلومات المفيدة التي موجودة في واجهات برمجة التطبيقات الموحدة مثل:
- وقت التنقّل 2
- وقت التلوين
nextHopProtocol
بالإضافة إلى توقيت التنقل 2 توقيت المورد 2.
وينفذ العديد من موردي المتصفحات واجهات برمجة التطبيقات الموحدة هذه. نتيجة لذلك، أُنشئت مكتبة مات بلوت ليب في
نتيجة لذلك، يتم إيقاف chrome.loadTimes()
نهائيًا في الإصدار Chrome 64.
واجهة برمجة التطبيقات التي تم إيقافها نهائيًا
تعرض الدالة chrome.loadTimes()
كائنًا واحدًا يحتوي على جميع
معلومات الشبكة والتحميل. على سبيل المثال، الكائن التالي هو النتيجة
للاتصال بـ chrome.loadTimes()
على www.google.com:
{
"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()
يعرض قيمًا للأوقات بالثواني وقت الفترة، بينما تعرض واجهات برمجة التطبيقات الجديدة للأداء
عادةً ما تُبلغ القيم بالمللي ثانية بالنسبة إلى قيمة
أصل الوقت، والذي يميل إلى
ستكون أكثر فائدة لتحليل الأداء.
وبعض الأمثلة تفضّل أيضًا واجهات برمجة تطبيقات الأداء الزمني 2 لواجهات برمجة التطبيقات (على سبيل المثال:
performance.getEntriesByType()
) ولكن توفير خيارات احتياطية للأقدم
واجهة برمجة تطبيقات Navigation Timing 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.loadTimes()
نهائيًا في الإصدار Chrome 64 والهدف منها هو
في أواخر عام 2018. على المطوّرين نقل الرموز في أقرب وقت ممكن.
لتجنب أي فقدان في البيانات.