performance - Is this a reasonable way to only include jquery plugins when they are needed? -


i'm creating website use in-house, using laravel , other things i've been wanting learn, given bit of freedom , it's more fun wordpress etc.

i want colleagues not overly web savvy able create pages , include nice functionality easily, instance know adding div class '.textcarousel', p tags within it, create styled carousel of p tags etc.

what don't want have (or think don't want have do, might preferable current 'solution' - why here) include ton of jquery plugins on every page if aren't going used.

what have done workaround (in pseudo-code here) this:

if(selector.length)     selector.each         var defaults = { ..., script: 'path/to/plugin' },             data = this.data(),             opts = extend(defaults, data),             tis  = this;          if(!opts.script.length)             head = document.getelementsbytagname('head')[0],             script = document.createelement('script');             script.src = opts.script;             head.appendchild(script);          if(opts.script.length && !$.fn.plugin)             script.on('load', *initplugin*)         else             tis.initplugin(opts) 

does seem ok way things or creating lots of unnecessary boilerplate , should include available plugins default?


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -