mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-27 15:50:34 +00:00
perf(core): ⚡️ defer background main scripts with requestIdleCallback
This commit is contained in:
parent
5431d1499a
commit
9556478443
|
@ -1,3 +1,22 @@
|
|||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
function deferredTasks() {
|
||||
const setupObservers = require( './setupObservers.js' );
|
||||
setupObservers.main();
|
||||
registerServiceWorker();
|
||||
|
||||
window.addEventListener( 'beforeunload', () => {
|
||||
// Set up loading indicator
|
||||
document.documentElement.classList.add( 'citizen-loading' );
|
||||
}, false );
|
||||
|
||||
// Remove loading indicator once the page is unloaded/hidden
|
||||
window.addEventListener( 'pagehide', () => {
|
||||
document.documentElement.classList.remove( 'citizen-loading' );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register service worker
|
||||
*
|
||||
|
@ -49,7 +68,6 @@ function main( window ) {
|
|||
echo = require( './echo.js' ),
|
||||
search = require( './search.js' ),
|
||||
dropdown = require( './dropdown.js' ),
|
||||
setupObservers = require( './setupObservers.js' ),
|
||||
lastModified = require( './lastModified.js' ),
|
||||
share = require( './share.js' );
|
||||
|
||||
|
@ -66,25 +84,13 @@ function main( window ) {
|
|||
} );
|
||||
|
||||
// Preference module
|
||||
if ( config.wgCitizenEnablePreferences === true && typeof document.createElement( 'div' ).prepend === 'function' ) {
|
||||
if ( config.wgCitizenEnablePreferences === true ) {
|
||||
mw.loader.load( 'skins.citizen.preferences' );
|
||||
}
|
||||
|
||||
// Defer non-essential tasks
|
||||
setTimeout( () => {
|
||||
setupObservers.main();
|
||||
registerServiceWorker();
|
||||
|
||||
window.addEventListener( 'beforeunload', () => {
|
||||
// Set up loading indicator
|
||||
document.documentElement.classList.add( 'citizen-loading' );
|
||||
}, false );
|
||||
|
||||
// Remove loading indicator once the page is unloaded/hidden
|
||||
window.addEventListener( 'pagehide', () => {
|
||||
document.documentElement.classList.remove( 'citizen-loading' );
|
||||
} );
|
||||
}, 0 );
|
||||
// eslint-disable-next-line compat/compat
|
||||
requestIdleCallback( deferredTasks, { timeout: 3000 } );
|
||||
}
|
||||
|
||||
if ( document.readyState === 'interactive' || document.readyState === 'complete' ) {
|
||||
|
|
Loading…
Reference in a new issue