load_script

load_script(js_filename, callback, onload)

domain: client

language: javascript

class AbstractItem

Description

Use load_script method to load javascript file from the server, before executing callback.

The method checks whether the file has been loaded, if not, loads it from the server, executes (if specified) onload function and then executes the callback, otherwise just the callback function is executed. The item is passed to the callback function as a parameter.

The js_filename should specify the path to javascript file relative to the server directory.

The request to the sever is executed asyncroniously.

Example

Bellow, the do_some_work function is executed only when lib.js file from server js directory has been loaded.

loaded:

function some_work(item) {
    item.load_script('js/lib.js', do_some_work);
}

function do_some_work(item) {
    // some code
}

See also

Working with modules

load_module

load_modules