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
This commit is contained in:
Ori Livneh 2015-04-09 11:34:24 -07:00
parent 0f76888310
commit c741db5378

View file

@ -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 ) {