Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中文文档 #7

Closed
lifesinger opened this issue Jun 29, 2013 · 0 comments
Closed

中文文档 #7

lifesinger opened this issue Jun 29, 2013 · 0 comments

Comments

@lifesinger
Copy link
Member

flush 插件

通过 combo 插件,我们可以对同一数组中的加载项进行合并加载。通过 flush 插件,我们可以更进一步减少 HTTP 请求数。

使用场景

看代码:

seajs.use('a');
seajs.use('b');
seajs.use('c');
seajs.use('d');

Sea.js 默认会发送 4 个独立请求。

如果能在 use 调用时不发送请求,等到多次 use 后,在合适的时机统一触发就好了。 这就是 flush 插件的用武之地。

使用方式

使用方式和 combo 插件一样,推荐以下方式:

<script src="http://test.com/??path/to/sea.js,path/to/seajs-combo.js,path/to/seajs-flush.js"></script>

注意:flush 插件一般和 combo 插件一起使用。

加载 flush 插件后,就具有了 seajs.flush 方法。我们可以在合适的时机触发 use 的下载:

seajs.use('a');
seajs.use('b');
seajs.use('c');
seajs.flush(); // 在此处触发前面的 use 下载:http://path/to/??a.js,b,js,c,js
seajs.use('d'); 
seajs.use('e');
seajs.flush(); // 此处触发的下载是:http://path/to/??d.js,e.js

通过上面的示例,我相信你已经明白了 flush 插件的奥妙。这可以让我们在下载时机的控制上更灵活自由。

测试页面

http://seajs.github.com/seajs/tests/specs/extensible/seajs-flush/test.html

参考


性能优化无极限。我相信通过 Sea.js 还可以进行很多其他优化,如果你有好的经验,欢迎以插件的方式分享出来。世界因分享而美丽。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant