own page load microopt: reduce blocking on prefs

postpone noncritical init stuff to window.load because first access to chrome API takes time to initialize API bindings
This commit is contained in:
tophf 2017-04-17 18:08:49 +03:00
parent eccabb8f27
commit 4eae87e606

View File

@ -146,8 +146,19 @@ var prefs = new function Prefs() {
} else { } else {
value = defaultValue; value = defaultValue;
} }
this.set(key, value, {noBroadcast: true}); if (BG == window) {
// when in bg page, .set() will write to localStorage
this.set(key, value, {noBroadcast: true, noSync: true});
} else {
values[key] = value;
defineReadonlyProperty(this.readOnlyValues, key, value);
} }
}
// any access to chrome API takes time due to initialization of bindings
let lazyInit = () => {
window.removeEventListener('load', lazyInit);
lazyInit = null;
getSync().get('settings', ({settings: synced} = {}) => { getSync().get('settings', ({settings: synced} = {}) => {
if (synced) { if (synced) {
@ -194,6 +205,10 @@ var prefs = new function Prefs() {
} }
} }
}); });
};
window.addEventListener('load', lazyInit);
return;
function doBroadcast() { function doBroadcast() {
const affects = {all: 'disableAll' in broadcastPrefs}; const affects = {all: 'disableAll' in broadcastPrefs};