Do not load unnecessary script files (#4193)
This commit is contained in:
parent
87b96f8d33
commit
9008ab3407
5 changed files with 39 additions and 28 deletions
|
@ -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'));
|
||||
|
||||
|
|
7
app/javascript/mastodon/ready.js
Normal file
7
app/javascript/mastodon/ready.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
export default function ready(loaded) {
|
||||
if (['interactive', 'complete'].includes(document.readyState)) {
|
||||
loaded();
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', loaded);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue