Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit c7ce5b3

Browse files
refactor: inject preload scripts with function call
1 parent db1cd35 commit c7ce5b3

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

project.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ export class Project {
260260
return [status, data]
261261
}
262262

263+
getPreloadScripts(baseUrl: string) {
264+
const scripts = [
265+
'-/deno.land/x/aleph/aleph.js',
266+
'-/deno.land/x/aleph/context.js',
267+
'-/deno.land/x/aleph/error.js',
268+
'-/deno.land/x/aleph/events.js',
269+
'-/deno.land/x/aleph/routing.js,',
270+
'-/deno.land/x/aleph/util.js'
271+
]
272+
return scripts.map(src => ({ src: `${baseUrl}${src}`, type: 'module', preload: true }))
273+
}
274+
263275
async getPageHtml(loc: { pathname: string, search?: string }): Promise<[number, string, Record<string, string> | null]> {
264276
if (!this.isSSRable(loc.pathname)) {
265277
const [url] = this.#routing.createRouter(loc)
@@ -275,11 +287,7 @@ export class Project {
275287
scripts: [
276288
data ? { type: 'application/json', innerText: JSON.stringify(data), id: 'ssr-data' } : '',
277289
{ src: util.cleanPath(`${baseUrl}/_aleph/main.${mainModule.hash.slice(0, hashShort)}.js`), type: 'module' },
278-
{ src: util.cleanPath(`${baseUrl}/_aleph/-/deno.land/x/aleph/nomodule.js${this.isDev ? '?dev' : ''}`), nomodule: true },
279-
{ src: util.cleanPath(`${baseUrl}/_aleph/-/deno.land/x/aleph/error.js`), type: 'module', preload: true },
280-
{ src: util.cleanPath(`${baseUrl}/_aleph/-/deno.land/x/aleph/aleph.js`), type: 'module', preload: true },
281-
{ src: util.cleanPath(`${baseUrl}/_aleph/-/deno.land/x/aleph/context.js`), type: 'module', preload: true },
282-
{ src: util.cleanPath(`${baseUrl}/_aleph/-/deno.land/x/aleph/events.js`), type: 'module', preload: true },
290+
...this.getPreloadScripts(baseUrl),
283291
...scripts
284292
],
285293
body,
@@ -297,6 +305,7 @@ export class Project {
297305
scripts: [
298306
{ src: util.cleanPath(`${baseUrl}/_aleph/main.${mainModule.hash.slice(0, hashShort)}.js`), type: 'module' },
299307
{ src: util.cleanPath(`${baseUrl}/_aleph/-/deno.land/x/aleph/nomodule.js${this.isDev ? '?dev' : ''}`), nomodule: true },
308+
...this.getPreloadScripts(baseUrl)
300309
],
301310
head: customLoading?.head || [],
302311
body: `<main>${customLoading?.body || ''}</main>`,
@@ -383,6 +392,7 @@ export class Project {
383392
data ? { type: 'application/json', innerText: JSON.stringify(data), id: 'ssr-data' } : '',
384393
{ src: util.cleanPath(`${baseUrl}/_aleph/main.${mainModule.hash.slice(0, hashShort)}.js`), type: 'module' },
385394
{ src: util.cleanPath(`${baseUrl}/_aleph/-/deno.land/x/aleph/nomodule.js${this.isDev ? '?dev' : ''}`), nomodule: true },
395+
...this.getPreloadScripts(baseUrl),
386396
...scripts
387397
],
388398
body,

0 commit comments

Comments
 (0)