backbone.js - 在需要时使用 require.js 加载 .js 文件
我发现了关于如何使用 require.js 组织文件和加载文件的有趣链接 http://backbonetutorials .com/organizing-backbone-using-modules/ ,我对该示例的唯一问题是它们从一开始就加载所有内容,甚至是异步的。我想知道是否可以仅在需要时加载 .js 文件...例如,如果我单击项目列表 ( http://backbonetutorials.com/examples/modular-backbone/#/projects ),它检查我们当前所在的网址,并在之后加载projects.js和list.js 那.... 对于小型应用程序来说这是可以的,但对于具有大类的大型应用程序来说,可能需要一段时间才能将所有路由器的所有类加载到浏览器中。
I found interesting link on how to organize my files and load files using require.js http://backbonetutorials.com/organizing-backbone-using-modules/ , the only issue I have with that example is that they load everything in the beginning even asynchronously. I was wondering if it is possible load .js files only when they needed... For example if I click on Project List ( http://backbonetutorials.com/examples/modular-backbone/#/projects ), it checks on which url we are currently located, and load projects.js and list.js after that....
For small apps it would be ok, but for big apps with big classes it might take a while, before all classes will be loaded to the browser, for all routers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为该示例的创建者更准确地回答了这个问题。这是他的答案: http://backbonetutorials.com/organizing-backbone-using -modules/#IDComment-CommentText210764496 ,查看回复
I think creator of that example answered this question more accurately. Here is his answer: http://backbonetutorials.com/organizing-backbone-using-modules/#IDComment-CommentText210764496 , see the reply
首先,您确实需要一个大型应用程序才能需要它。普通应用程序的文件(经过压缩和压缩)并不是很大的负载。然后您可以使用缓存在每个浏览器中仅加载它们一次。
如果你真的愿意,当然可以进行部分加载,就像示例中的应用程序一样(在路由器中,
projects
路由会首先确保项目相关的 js文件被加载,然后才进行获取/视图初始化等)First of all, you would really need a big application in order to need that. The files of a normal application, minified and gzipped, are not a significant load. And then you can use caching to load them only once in each browser.
If you really want to, of course you can do partial loading, in the same way you do it for the application in the example (in the router, the
projects
route will first ensure the project-related js files are loaded, and only then do the fetching/view initialization etc)