0
0
Fork 0

Do not load unnecessary script files (#4193)

This commit is contained in:
Yamagishi Kazutoshi 2017-07-14 18:08:56 +09:00 committed by Eugen Rochko
parent 87b96f8d33
commit 9008ab3407
5 changed files with 39 additions and 28 deletions

View file

@ -1,12 +1,6 @@
const perf = require('./performance');
import ready from './ready';
function onDomContentLoaded(callback) {
if (document.readyState !== 'loading') {
callback();
} else {
document.addEventListener('DOMContentLoaded', callback);
}
}
const perf = require('./performance');
function main() {
perf.start('main()');
@ -24,7 +18,7 @@ function main() {
}
}
onDomContentLoaded(() => {
ready(() => {
const mountNode = document.getElementById('mastodon');
const props = JSON.parse(mountNode.getAttribute('data-props'));

View file

@ -0,0 +1,7 @@
export default function ready(loaded) {
if (['interactive', 'complete'].includes(document.readyState)) {
loaded();
} else {
document.addEventListener('DOMContentLoaded', loaded);
}
}