From 901fc02d78c3d5d8755e2b68f92d97b7ba7118b8 Mon Sep 17 00:00:00 2001 From: shadowtime2000 <66655515+shadowtime2000@users.noreply.github.com> Date: Mon, 2 Nov 2020 17:34:46 -0800 Subject: [PATCH 1/6] feat: preload all scripts --- html.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html.ts b/html.ts index ef55a23f1..6366355a1 100644 --- a/html.ts +++ b/html.ts @@ -20,7 +20,7 @@ export function createHtml({ if (!util.isString(v) && util.isNEString(v.src)) { if (v.type === 'module') { return `` - } else if (v.async === true) { + } else { return `` } } From fbd3b5f3cb6e401314b0f52900c7c46e145b21f8 Mon Sep 17 00:00:00 2001 From: shadowtime2000 <66655515+shadowtime2000@users.noreply.github.com> Date: Mon, 2 Nov 2020 17:44:12 -0800 Subject: [PATCH 2/6] refactor: a refactor --- html.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/html.ts b/html.ts index 6366355a1..e5793b7fc 100644 --- a/html.ts +++ b/html.ts @@ -20,9 +20,8 @@ export function createHtml({ if (!util.isString(v) && util.isNEString(v.src)) { if (v.type === 'module') { return `` - } else { - return `` } + return `` } return '' })).filter(Boolean) From 82e6d68b3035a89d81d2786ee1f5fa51b684a33b Mon Sep 17 00:00:00 2001 From: shadowtime2000 <66655515+shadowtime2000@users.noreply.github.com> Date: Mon, 2 Nov 2020 18:32:29 -0800 Subject: [PATCH 3/6] feat: preload aleph library files --- html.ts | 96 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/html.ts b/html.ts index e5793b7fc..43c720942 100644 --- a/html.ts +++ b/html.ts @@ -1,64 +1,86 @@ -import util from './util.ts' +import util from "./util.ts"; export function createHtml({ - lang = 'en', + lang = "en", head = [], scripts = [], body, - minify = false + minify = false, }: { - lang?: string, - head?: string[], - scripts?: (string | { id?: string, type?: string, src?: string, innerText?: string, nomodule?: boolean, async?: boolean, preload?: boolean })[], - body: string, - minify?: boolean + lang?: string; + head?: string[]; + scripts?: + (string | { + id?: string; + type?: string; + src?: string; + innerText?: string; + nomodule?: boolean; + async?: boolean; + preload?: boolean; + })[]; + body: string; + minify?: boolean; }) { - const eol = minify ? '' : '\n' - const indent = minify ? '' : ' '.repeat(4) - const headTags = head.map(tag => tag.trim()) - .concat(scripts.map(v => { + const eol = minify ? "" : "\n"; + const indent = minify ? "" : " ".repeat(4); + const headTags = head.map((tag) => tag.trim()) + .concat(scripts.map((v) => { if (!util.isString(v) && util.isNEString(v.src)) { - if (v.type === 'module') { - return `` + if (v.type === "module") { + return ``; } - return `` + return ``; } - return '' - })).filter(Boolean) - const scriptTags = scripts.map(v => { + return ""; + })) + .concat( + [ + "/_aleph/-/deno.land/x/aleph/error.js", + "/_aleph/-/deno.land/x/aleph/aleph.js", + "/_aleph/-/deno.land/x/aleph/context.js", + "/_aleph/-/deno.land/x/aleph/events.js" + ].map((v) => + `` + ), + ) + .filter(Boolean); + const scriptTags = scripts.map((v) => { if (util.isString(v)) { - return `` + return ``; } else if (util.isNEString(v.innerText)) { - const { innerText, ...rest } = v - return `` + const { innerText, ...rest } = v; + return ``; } else if (util.isNEString(v.src) && !v.preload) { - return `` + return ``; } else { - return '' + return ""; } - }).filter(Boolean) + }).filter(Boolean); return [ - '', + "", ``, - '
', + "", indent + '', - ...headTags.map(tag => indent + tag), - '', - '', + ...headTags.map((tag) => indent + tag), + "", + "", indent + body, - ...scriptTags.map(tag => indent + tag), - '', - '' - ].join(eol) + ...scriptTags.map((tag) => indent + tag), + "", + "