You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
加载 flush 插件后,就具有了 seajs.flush 方法。我们可以在合适的时机触发 use 的下载:
seajs.use('a');seajs.use('b');seajs.use('c');seajs.flush();// 在此处触发前面的 use 下载:http://path/to/??a.js,b,js,c,jsseajs.use('d');seajs.use('e');seajs.flush();// 此处触发的下载是:http://path/to/??d.js,e.js
flush 插件
通过 combo 插件,我们可以对同一数组中的加载项进行合并加载。通过 flush 插件,我们可以更进一步减少 HTTP 请求数。
使用场景
看代码:
Sea.js 默认会发送 4 个独立请求。
如果能在
use
调用时不发送请求,等到多次use
后,在合适的时机统一触发就好了。 这就是 flush 插件的用武之地。使用方式
使用方式和 combo 插件一样,推荐以下方式:
注意:flush 插件一般和 combo 插件一起使用。
加载 flush 插件后,就具有了
seajs.flush
方法。我们可以在合适的时机触发use
的下载:通过上面的示例,我相信你已经明白了 flush 插件的奥妙。这可以让我们在下载时机的控制上更灵活自由。
测试页面
http://seajs.github.com/seajs/tests/specs/extensible/seajs-flush/test.html
参考
性能优化无极限。我相信通过 Sea.js 还可以进行很多其他优化,如果你有好的经验,欢迎以插件的方式分享出来。世界因分享而美丽。
The text was updated successfully, but these errors were encountered: