Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple jQuery Plugin Loader
$.load = function(options){
// check for something to load
if(options.src === undefined) return;
// load dependencies
if(options.deps !== undefined){
$.each(options.deps, function(key, value){
var type = value.split(".")[value.split(".").length - 1];
if(type === "js"){
}else if(type === "css"){
var css = document.createElement("link");
css.rel = "stylesheet";
css.href = value;
// append the new element
// load the script
$.getScript(options.src, function(){
// run the callback function if there is one
if(options.callback !== undefined){
src: "js/jquery.plugin.js", // the location of the script relative to the page (required)
deps: ["css/plugin.css", "js/jquery.dependecy.js"], // dependencies of the script (optional),
callback: function(){ // will run after the plugin has loaded (optional)
// do stuff with your plugin here

This comment has been minimized.

Copy link

commented Sep 23, 2016


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.