In Dojo or CommonJS, frameworks based on it are not a problem at all. Javascript code is usually stored in a module.
In our IDE web environment, we reload scripts (@reloadCustomMobileStack) all the time:
define([ 'dojo/_base/declare', 'require' ], function(declare,require) { return dojo.declare("xappstudio.manager.DynamicScriptMixin", null, { _reloadModule:function(module,reload) { require.undef(module); var scripts = document.getElementsByTagName('script'); for (var i = scripts.length - 1; i >= 0; i--) { var script = scripts[i]; if (script.getAttribute('src') && script.getAttribute('src').length > 0 && script.getAttribute('src').indexOf(module)!=-1) { script.parentNode.removeChild(script); break; } } if(reload) { require([module], function(_moduleIn) { console.error('got module' + _moduleIn); }); } }, reloadCustomMobileStack:function() { var modulesToReload = [ 'cxapp/delegates/BootDelegate', 'cxapp/delegates/FormDelegate', 'cxapp/delegates/HeaderToolbarDelegate', 'cxapp/delegates/ImageResizeDelegate', 'cxapp/delegates/ServiceDelegate', 'cxapp/delegates/UrlDelegate', 'cxapp/manager/Context', 'cxapp/manager/CustomApplication', 'cxapp/manager/DataManager', 'cxapp/types/Types', 'cxapp/utils/RPCProxyPOSTEnvelope' ]; for(var i = 0 ; i < modulesToReload.length ; i++) { this._reloadModule(modulesToReload[i],true); } } }); });
To use "require.undef (module)"; you must add this here to your Dojo config: "has: {'dojo -undef-api: true}"
Of course, this will not work with any Javascript, since Dojo / Common-JS Javascript is different, but it allows you to inject or enable dependency as well.
source share