Load JavaScript Files BX24.loadScript
Choose a tool for developing with an AI agent:
- use Alaio Vibecode to build an app for Bitrix24 from a task description without knowing any programming language. The agent writes the code and deploys the app to a server, with no manual hosting setup
- use the MCP server to develop a REST API integration in your own project. The agent refers to the official REST documentation
BX24.loadScript(script: string | array, callback?: callable): void;
The BX24.loadScript method adds one or more JavaScript files to the application page and executes them. Files from an array are loaded in sequence: each file is loaded after the previous one has finished loading. This way, you can add a library and then a script that uses it.
If the page is not ready yet, the method itself waits for page readiness — the same moment when the BX24.ready handlers run. The method does not call Bitrix24, so you do not need to wait for BX24.init. The method requires no scope of its own.
If a file fails to load, for example, because it is not on the server, the method stops without an error: the remaining files are not loaded, and callback is not called. The loading failure is visible in the browser console.
Method Parameters
Required parameters are marked with *
|
Name |
Description |
|
script* |
The address of a JavaScript file or an array of addresses. The browser resolves a relative address the same way as for a |
|
callback |
Callback function. It is called without parameters when all files are loaded |
Code Example
How to Use Examples in Documentation
Load a charting library, then a report script that uses it:
BX24.loadScript(
[
'js/chart.min.js',
'js/report.js'
],
function () {
console.log('All scripts have been loaded');
}
);
Response Handling
The method does not return data (void). When the last file has loaded, the library calls callback without parameters. If the page is already ready and an empty array is passed, callback runs immediately.
Error Handling
The method does not return error codes.
|
Situation |
What Happens |
What to Do |
|
A file failed to load: it is not on the server, or the network connection was lost |
Loading stops silently, as described in the warning above |
Check the file addresses. If the application needs to know about the failure, limit the wait for |
|
A file contains a syntax error |
The browser does not execute this file, but loading continues, and |
Do not treat the |
|
|
A |
Pass a file address or an array of addresses |
|
Something other than a function is passed as |
The files load without an error, but no call is made |
Pass a function |
|
An empty string or an array of empty strings is passed as |
No files are loaded, there is no error, and |
If the addresses are built in code, check them before the call |