合并多个javascript文件 [英] Merging multiple javascript files

查看:107
本文介绍了合并多个javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过将几个多个javascript文件合并到一个文件中可以提高性能,这是真的吗?

I've read that merging several multiple javascript files into a single file improves performance, is that true?

如果是这样,是否有一种简单且无错误的方法来合并它们,或者是一种自动执行此操作的在线工具?

If so, is there an easy and error-free way of merging them, or perhaps an online-tool that automatically does that?

非常感谢。

推荐答案

参见多个javascript / css文件:最佳做法?用PHP增加Javascript

简短的回答是你想要最小化外部HTTP请求。最好的方法是强制浏览器缓存服务器上的文件,直到它们发生变化。您可以通过对文件进行版本控制并提供远期的Expires标头来实现此目的。当文件名发生变化时(通过更改版本),浏览器将获得新版本。

The short answer is that you want to minimize external HTTP requests. The best way to do that is to force the browser to cache files you server until they change. You do this by versioning the files and providing a far future Expires header. When the filename changes (by changing the version) the browser will get the new version.

如果你这样做,那么多个Javascript文件并不重要。但是,如果您强制客户端在每个页面上下载27个JS文件而不进行缓存,那么减少文件数量可能会产生重大影响。当然,这仍然不如有效的缓存/版本控制策略。

If you do this then multiple Javascript files don't really matter. But if you force the client to download 27 JS files on each and every page with no caching then reducing the number of files can make a substantial difference. Of course this is still inferior to effective caching/versioning strategies.

另一个需要考虑的问题是 iphone缓存

Another more recent issue to consider is iphone caching:


iPhone不会缓存组件
大于15K(前一个实验
为25K)

iPhone will not cache components bigger than 15K (was 25K in the previous experiment)

所以在某些情况下组合文件可能是有害的。

So in some circumstances combining files can be detrimental.

这篇关于合并多个javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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