📜 ⬆️ ⬇️

Load on demand and jQuery

Despite the fact that it is necessary to minimize the number of http-requests, sometimes (or often, depending on the task) it is useful to download some of the “heavy” functionality only when it is really needed on the page.
JQuery has a mechanism to do this - $.getS cript , however, it has several disadvantages:I had to write a small plugin, devoid of the above disadvantages:

$.requireS cript( url , callback , [ context ], [ options ])
Where:
url - the URL of the loaded script (maybe an array of URLs)
callback - callback function that is called after loading scripts
context - the context in which the callback function is called (optional)
options - parameters; currently only one parameter is supported - parallel , indicating whether parallel loading should be used for several scripts ( true by default)


Maybe someone will come in handy. Download and try with code.google .
')
UPDATE: according to the comments in the comments, $.loadS cript renamed to $.requireS cript , and now you can specify several URLs at once.

Source: https://habr.com/ru/post/60090/


All Articles