Loading script scripts with jquery

Source: Internet
Author: User
Tags getscript

Original link: Loading Scripts with JQuery

The JavaScript loaders Loader is simple, powerful, and very useful. I've introduced some of them on my blog, such as Curljs and LABJS, and also used Requirejs and Dojo loaders in personal projects. They are so powerful, but in some cases it may be overkill. If you're using jquery, you'll find that jquery has built-in methods for loading a single script, which might come in handy if you want to defer loading plugins or other types of scripts. Here's how to use it!

The JQuery JavaScript
jquery provides a getScript method for loading scripts, and results can be processed in several ways. The basic usage of Jquery.getscript is as follows:

    Jquery.getscript ("/path/to/myscript.js", function (data, status, JQXHR) {/          * When the script is loaded and executed, you can perform some special processing here. */      });  

The callback function of the Getscript method provides a jqxhr parameter. Of course, it can be handled as follows:

    Jquery.getscript ("/path/to/myscript.js")          . Done (function () {              /* * Load succeeded          /})          . Fail (function () {              / * Load failed, do fall back processing */      });  

The most common usage scenario for jquery.getscript is to delay loading a plug-in and use it after the load is complete:

    Jquery.getscript ("Jquery.cookie.js")          . Done (function () {              Jquery.cookie ("Cookie_name", "value", {expires:7 });      });  

If you need more advanced loading capabilities, such as loading multiple scripts at the same time, or loading different types of files (text, images, CSS, etc.), you should switch to a JavaScript loader.
Sometimes we want to delay loading a plugin after a certain condition is met, so $.getscript is a great solution.

Original link: http://blog.csdn.net/renfufei/article/details/18039237

Loading script scripts with jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.