logologo
Get Started
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Italiano
Türkçe
Українська
Tiếng Việt
Bahasa Indonesia
ไทย
Polski
Nederlands
Čeština
العربية
עברית
हिन्दी
Svenska
Get Started
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Import Modules
Render in Container

Globals

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.request()
Next Pagectx.resource

#ctx.requireAsync()

Load UMD/AMD or global scripts by URL, and also supports CSS. Suitable for JS blocks/fields/actions. Use ctx.requireAsync() for UMD/AMD libraries, and ctx.importAsync() for ESM libraries. Passing a .css URL will load and inject styles.

#Type definition

requireAsync<T = any>(url: string): Promise<T>;

#Parameters

ParameterTypeDescription
urlstringSupports two forms: shorthand path <package>@<version>/<file> (same as ctx.importAsync(), resolved via ESM CDN and requested with ?raw for the UMD file), or a full URL (e.g. https://cdn.jsdelivr.net/npm/xxx). .css URLs are also supported and will be injected.

#Return value

  • The loaded library object (format depends on the library). Many UMD libraries attach to globals (e.g. window.xxx).

#Notes

  • UMD/AMD and CSS: besides UMD/AMD scripts, CSS loading is supported.
  • Shorthand: for example echarts@5/dist/echarts.min.js becomes https://esm.sh/echarts@5/dist/echarts.min.js?raw by default.
  • Full URL: any CDN URL can be used directly.

#Example

// Shorthand path (resolved via esm.sh with ?raw)
const echarts = await ctx.requireAsync('echarts@5/dist/echarts.min.js');

// Full URL
const dayjs = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js');

// Load CSS and inject
await ctx.requireAsync('https://cdn.example.com/theme.css');

#Difference from ctx.importAsync()

  • ctx.requireAsync(): loads UMD/AMD/global scripts, suitable for ECharts, FullCalendar, jQuery plugins, etc. Libraries often attach to window.
  • ctx.importAsync(): loads ESM modules and returns module namespace. If an ESM build exists, prefer ctx.importAsync() for better module semantics and tree-shaking.