Async JavaScript load

This commit is contained in:
Eduard Urbach 2018-04-24 13:29:46 +02:00
parent c7f482c525
commit e63be2c43a
4 changed files with 26 additions and 10 deletions

View File

@ -54,7 +54,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
ExtensionNavigation(user)
if user != nil
#user(data-id=user.ID, data-pro=user.IsPro(), data-theme=user.Settings().Theme)
script(src="/scripts")
script(src="/scripts", async="async")
script(type="application/ld+json")!= organization
component Content(content string)

View File

@ -3,7 +3,12 @@ import AnimeNotifier from "../AnimeNotifier"
// Chrome extension installation
export function installExtension(arn: AnimeNotifier, button: HTMLElement) {
let browser: any = window["chrome"]
if(browser && browser.webstore) {
browser.webstore.install()
} else {
window.open("https://chrome.google.com/webstore/detail/anime-notifier/hajchfikckiofgilinkpifobdbiajfch", "_blank")
}
}
// Desktop app installation

View File

@ -83,9 +83,13 @@ export default class AnimeNotifier {
// Event listeners
document.addEventListener("readystatechange", this.onReadyStateChange.bind(this))
document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this))
document.addEventListener("keydown", this.onKeyDown.bind(this), false)
window.addEventListener("popstate", this.onPopState.bind(this))
window.addEventListener("error", this.onError.bind(this))
// If we finished loading the DOM (either "interactive" or "complete" state),
// immediately trigger the event listener functions.
if(document.readyState !== "loading") {
this.app.emit("DOMContentLoaded")
this.run()
}
// Idle
requestIdleCallback(this.onIdle.bind(this))
@ -176,6 +180,11 @@ export default class AnimeNotifier {
}
async onIdle() {
// Register event listeners
document.addEventListener("keydown", this.onKeyDown.bind(this), false)
window.addEventListener("popstate", this.onPopState.bind(this))
window.addEventListener("error", this.onError.bind(this))
// Service worker
this.serviceWorkerManager = new ServiceWorkerManager(this, "/service-worker")
this.serviceWorkerManager.register()

View File

@ -26,12 +26,14 @@ export default class Application {
}
init() {
document.addEventListener("DOMContentLoaded", () => {
document.addEventListener("DOMContentLoaded", this.onContentLoaded.bind(this))
}
onContentLoaded() {
let links = document.getElementsByTagName("a")
this.markActiveLinks(links)
this.ajaxify(links)
})
}
get(url: string): Promise<string> {