In BoilerplateJS browser is loading all the script

2019-06-24 11:53发布

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条回答
smile是对你的礼貌
2楼-- · 2019-06-24 12:39

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.

查看更多
登录 后发表回答