Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/247526

Change subject: Record TTFI, or time-to-first-image
......................................................................

Record TTFI, or time-to-first-image

Use the Resource Timing API to record the time (in milliseconds) which elapsed
from navigationStart until the first image which is part of the article content
has finished loading. If no such image exists, or if the Resource Timing API is
not available, omit the metric.

Bug: T115600
Change-Id: Ia5652a0ee8c822398beb48e72b9844ba9ccf8ba2
---
M NavigationTiming.php
M modules/ext.navigationTiming.js
2 files changed, 32 insertions(+), 2 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NavigationTiming 
refs/changes/26/247526/1

diff --git a/NavigationTiming.php b/NavigationTiming.php
index fc9daab..047993f 100644
--- a/NavigationTiming.php
+++ b/NavigationTiming.php
@@ -54,7 +54,7 @@
        $wgEventLoggingSchemas = array();
 }
 $wgEventLoggingSchemas += array(
-       'NavigationTiming' => 13317958,
+       'NavigationTiming' => 14214565,
        'SaveTiming'       => 12236257,
 );
 
diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js
index 9c5e38f..521864e 100644
--- a/modules/ext.navigationTiming.js
+++ b/modules/ext.navigationTiming.js
@@ -24,6 +24,31 @@
        }
 
        /**
+        * Get time-to-first-image -- the time (in milliseconds) which elapsed 
until
+        * the first thumbnail image has finished loading.
+        *
+        * @return {number|boolean} Time in milliseconds, or false if 
indeterminate.
+        */
+       function getTTFI() {
+               var ttfi;
+
+               try {
+                       ttfi = performance.getEntriesByType( 'resource' 
).filter( function ( entry ) {
+                               // We want to know about images which have 
finished loading and whose URL
+                               // indicates that they are thumbnails 
accompanying the article text (as
+                               // opposed to interface images, which are far 
more likely to be cached.)
+                               return entry.initiatorType === 'img'
+                                       && entry.responseEnd > 0
+                                       && 
/\/\/upload.wikimedia.org.*\/thumb\//.test( entry.name );
+                       } ).reduce( function ( previous, current ) {
+                               return Math.min( previous, current.responseEnd 
);
+                       }, Infinity );
+               } catch ( e ) {}
+
+               return ttfi && isFinite( ttfi ) ? ttfi : false;
+       }
+
+       /**
         * Assert that the attribute order complies with the W3C spec
         *
         * @return {boolean}
@@ -111,7 +136,8 @@
                                action: mw.config.get( 'wgAction' ) // view, 
submit, etc.
                        },
                        isSpecialPage = !!mw.config.get( 
'wgCanonicalSpecialPageName' ),
-                       mobileMode = mw.config.get( 'wgMFMode' );
+                       mobileMode = mw.config.get( 'wgMFMode' ),
+                       ttfi = getTTFI();
 
                if ( window.mediaWikiLoadStart ) {
                        event.mediaWikiLoadComplete = Math.round( 
mediaWikiLoadEnd - mediaWikiLoadStart );
@@ -137,6 +163,10 @@
                        event.mobileMode = mobileMode;
                }
 
+               if ( ttfi ) {
+                       event.TTFI = ttfi;
+               }
+
                $.extend( event, getNavTiming() );
                if ( navigation && navigation.type === 0 && !isCompliant() ) {
                        // Keep track of non-compliant browsers (only on 
TYPE_NAVIGATE)

-- 
To view, visit https://gerrit.wikimedia.org/r/247526
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia5652a0ee8c822398beb48e72b9844ba9ccf8ba2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/NavigationTiming
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to