-
Notifications
You must be signed in to change notification settings - Fork 0
load
load()
is a helper to include JavaScript files dynamically based on the general infrastructure of io()
.
Don't forget to consult the cookbook to see working snippets solving simple real-world problems.
io.load()
is modelled on io.get()
. It supports the same arguments and returns a promise.
io.load()
creates a script element. It takes two arguments:
-
url
is a URL as a string. -
options
is an options object described above (seeio()
). -
query
is an optional dictionary to form a query string (seequery
above inio()
).
Either url
or options
should be specified.
The returned value is a promise (see io()
for details).
io.load()
does not return any value, so a promise will be resolved with undefined
.
One obvious difference is the lack of an XHR object. Everywhere it is expected, null
is used.
Following helper methods, which are defined in io
are not used:
-
io.processData()
— we cannot send any payload. -
io.request()
— we do not use XHR. -
io.processSuccess()
— we don't need to extract data from XHR using different formats, because it is already provided.
Because io.load()
does not participate in the main io
workflow, it is not affected by high-level tools like io.bundle
.
Certain optional properties of options
are ignored completely:
-
method
— only one method is supported: GET. -
headers
— there is no way to define or change HTTP headers. -
user
andpassword
— unless it is encoded in a URL, a script element cannot pass a user name. -
timeout
,responseType
,withCredentials
,mime
— XHR-specific settings cannot be used. -
wait
,cache
,bundle
— all advanced tools are bypassed. -
processSuccess
— this function extracts data from XHR, while a script does not return any.
While an XHR request can be canceled, a script request cannot. No progress requests are sent out either.