mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
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:
parent
0f76888310
commit
c741db5378
|
@ -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 ) {
|
||||
|
|
Loading…
Reference in a new issue