在BoilerplateJS浏览器中加载所有脚本(在其他模块中),无论模块是否已激活 [英] In BoilerplateJS browser is loading all the scripts (in other modules) regardless of the module activated

查看:111
本文介绍了在BoilerplateJS浏览器中加载所有脚本(在其他模块中),无论模块是否已激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BoilerplatJS 网站上托管的示例项目中,当我们激活特定的示例模块时(例如clickCounter) )其他模块中的所有脚本(component.js,viewmodel.js和其他模块)都在浏览器中加载。

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?

谢谢!

推荐答案

这里有几点需要注意。

There are few things to note here.


  • 首先关于加载的文件:在生产部署中,所有这些文件将被BoilerplateJS组合,缩小和混淆优化。这意味着,无论如何,所有代码都将在生产中的单个脚本中,这在AMD JavaScript应用程序中是正常的。

  • 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.

即使代码已加载,个人也是如此在从前端控制器接收激活调用之前,不会呈现组件。您的模块将在初始应用程序加载时注册UI组件,但UI组件的实际创建仅在组件的激活功能中发生。这将确保应用程序加载时间更快,并且只在需要时才创建UI组件。

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.

您永远不应该依赖应用程序中的客户端授权。您的所有JS代码都将转到客户端浏览器,并且有可能被修改。但为了用户友好,您可以隐藏对用户不可接受的操作。在哪里做它取决于控制的粒度。如果您想在组件级别使用它,可以在导航菜单上进行此操作。

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.

这篇关于在BoilerplateJS浏览器中加载所有脚本(在其他模块中),无论模块是否已激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆