[英]What can I do if my Backbone main.js is too big?
I use require.js (AMD) and optimize it into one final javascript file (main.js) 我使用require.js(AMD)并将其优化为一个最终的javascript文件(main.js)
My main.js is half a megabyte, and it will continue to increase. 我的main.js是半兆字节,它会继续增加。
The problem is: when the client loads my backbone app, they must first download the entire half megabyte file before they can browse the site. 问题是:当客户端加载我的骨干应用程序时,他们必须首先下载整个半兆字节文件才能浏览网站。 (the router is included inside the file)
(路由器包含在文件中)
Oftentimes this can take 3 seconds before the initial load. 通常,这可能需要在初始加载之前3秒。
What can I do? 我能做什么?
Split your code up into the following categories and use separate requirejs modules for each. 将代码拆分为以下类别,并为每个类别使用单独的requirejs模块。
That way with a single, hopefully reasonably sized request, your app is up and running. 这样,只需一个希望合理大小的请求,您的应用就会启动并运行。 A second request takes another second or so to get you 98% loaded, and the last 2% trickles in on-demand if a given user needs it.
第二个请求需要另外一秒左右才能使您获得98%的负载,如果给定用户需要,则最后2%请求按需流入。
Requirejs has facilities for doing this via the config file. Requirejs具有通过配置文件执行此操作的工具。 It just takes some forethought and testing to find the right places to draw the dividing lines for your specific application.
只需要进行一些预见和测试,找到适合您特定应用的划分线的正确位置。
General tips: consider fewer large third party dependencies. 一般提示:考虑较少的大型第三方依赖项。 Consider a separate bundle for administrators if you have different user roles.
如果您有不同的用户角色,请考虑为管理员使用单独的捆绑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.