Merging multiple javascript files

前端 未结 4 2032
暗喜
暗喜 2021-01-31 21:38

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 t

4条回答
  •  臣服心动
    2021-01-31 21:48

    See Multiple javascript/css files: best practices? and Supercharging Javascript in PHP.

    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.

    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.

    Another more recent issue to consider is iphone caching:

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

    So in some circumstances combining files can be detrimental.

提交回复
热议问题