In BoilerplateJS browser is loading all the scripts (in other modules) regardless of the module activated

一个人想着一个人 提交于 2020-01-03 17:09:06

问题


In the example project hosted at BoilerplatJS site, when we activate a particular sample module (for example clickCounter) all the scripts in other modules (component.js, viewmodel.js and others) gets loaded in the browser.

How to restrict this behavior in case we have to limit modules to users based on some kind of authorization?

Thanks!


回答1:


There are few things to note here.

  • First regarding the files that load: In your production deployment, all these files will be combined, minified and obfuscated by the BoilerplateJS optimizer. Meaning, anyway all your code will be in a single script in production, this is normal in AMD JavaScript applications.

  • Even though the code are loaded, the individual components will not be rendered until they receive an activation call from a front controller. Your module will register the UI components, at the initial application load time, but real creation of the UI component happens only in the 'activate' function of your component. This will ensure the application load time is faster and UI component creation happens only on demand.

  • You should never depend on client side authorization in the application. All your JS code will go to the client browser and has potential to get modified. But for user friendliness, you may hide operation that are not permisible to the user. Where to do it depends on the granularity of control. If you want it at component level, you may do this on the navigation menu itself.



来源:https://stackoverflow.com/questions/12366823/in-boilerplatejs-browser-is-loading-all-the-scripts-in-other-modules-regardles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!