From c741db537832361e7be3a365e0b3561370b8234a Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Thu, 9 Apr 2015 11:34:24 -0700 Subject: [PATCH] Pre-fetch RESTBase DNS and negotiate TLS Keep VisualEditor load times snappy by eagerly establishing a connection with RESTBase via a beacon request, which is deferred until after window.onload / setTimeout to ensure it does not slow down the loading of the page. Task: T94784 Change-Id: I19fd2ef6beffe1c4c4f05c2716da079b49e88b95 --- .../targets/ve.init.mw.ViewPageTarget.init.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js index 7ce7aa33a6..a441d94dba 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js @@ -524,6 +524,19 @@ mw.config.get( 'wgPageContentModel' ) === 'wikitext' ); + // Pre-fetch RESTBase DNS and negotiate TLS. + function restbasePreConnect() { + var url, a = document.createElement( 'a' ); + + a.href = conf.restbaseUrl; + url = '//' + a.hostname + '/' + mw.config.get( 'wgServerName' ) + '/v1/'; + if ( navigator.sendBeacon ) { + navigator.sendBeacon( url ); + } else { + new Image().src = url; + } + } + // Note: Though VisualEditor itself only needs this exposure for a very small reason // (namely to access init.blacklist from the unit tests...) this has become one of the nicest // ways to easily detect whether the VisualEditor initialisation code is present. @@ -560,6 +573,11 @@ if ( userPrefEnabled ) { init.setupSkin(); + if ( conf.restbaseUrl ) { + $( window ).load( function () { + setTimeout( restbasePreConnect ); + } ); + } } if ( currentUri.query.venotify ) {