Skip to content

remote.Function.mountRemote

github-actions[bot] edited this page Jun 8, 2026 · 2 revisions

@zenstone/ts-utils / remote / mountRemote

Function: mountRemote()

mountRemote<K>(scope, options): Promise<MountRemoteResult<Record<string, unknown>>>

Defined in: src/remote/mountRemote.ts:304

挂载远程资源

基于 scope 做 inflight 去重:并发调用同 scope 只执行一次,结果共享。 Options 类型由 type 字段决定,通过 MountHandlerMap 接口扩展。

内置支持 jsmjscss 三种类型,其他类型需通过 registerMountHandler 注册处理器。

Type Parameters

K

K extends keyof MountHandlerMap

Parameters

scope

string

去重标识,同时用作 DOM 元素 id(对于 DOM handler)

options

object & Parameters<MountHandlerMap[K]>[1]

挂载选项,类型由 type 决定

Returns

Promise<MountRemoteResult<Record<string, unknown>>>

Examples

await mountRemote('jquery', {
  type: 'js',
  url: 'https://cdn.example.com/jquery.min.js',
});

并发去重

await Promise.all([
  mountRemote('lib', { type: 'js', url }),
  mountRemote('lib', { type: 'js', url }),
]);
// 只加载一次

Clone this wiki locally