yui - Avoid duplicate JavaScript in YUI3 -


i created 3 widgets added yui modules. widgets use same javascript library (commons.js) using y.get.js method. these widgets defined in separate js files (i need these widgets standalone). of them loaded html file , rendered. however, inspecting elements of html file in browser, turns out commons.js file included 3 times in html file, different ids:

<script charset="utf-8" id="yui_3_5_0_1_1374466627361_24" src="js/common.js"></script> <script charset="utf-8" id="yui_3_5_0_1_1374466627361_32" src="js/common.js"></script> <script charset="utf-8" id="yui_3_5_0_1_1374466627361_38" src="js/common.js"></script> 

is there way in yui avoid duplication? thank you!

y.get.js called when include module if used in module's body.

here suggestions:

  • put contents of common.js yui module. best choice
  • use yui load , wrap automatically module:

example:

yui({   modules: {     'my-common': {       fullpath: 'js/common.js',       requires: []     }   },   onprogress: function (e) {     (var _module, = 0, length = e.data.length; < length; i++) {       _module = e.data[i];       if (_module.name === 'my-common') {         yui.add('my-common', function (y) {           y.mycommon = mycommon;         });       }     }   } }).use('my-common', function (y) {   // ... }); 
  • load module yui().use() callback using y.get.js:

example:

yui(/* ... */).use('some-module', function (y) {   y.get.js('js/common.js', function () {     // rest of stuff   }); }); 
  • check if it's loaded before loading it

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -