将javascripts组合到一个文件中 [英] Combining javascripts into a single file

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

问题描述

最近阅读了雅虎的网络优化提示和使用YSlow我已经在我的一个网站上实现了他们的一些想法 http://www.gwynfryncottages.com 您可以在此处查看文件 http://www.gwynfryncottages.com/js/gw-custom.js



虽然这种技术似乎在大多数情况下都能很好地工作,并且确实加快了网站的速度,但我确实注意到javascripts没有出现明显更多的错误在我在网站上工作时加载或不完全加载所以三个问题: -




  • 以这种方式组合脚本在可靠性方面一个好主意?


  • 有没有办法衡量错误的数量,即脚本加载失败的次数? / p>


  • 有没有办法'预加载'javascript或确保加载错误的数量减少?



解决方案

当然这很好。您不仅会减少HTTP请求,还会减少下载其他资源的延迟。



尝试使用minify: http://code.google.com/p/minify/ ,我一直在使用它,我没有抱怨。



我可以向你保证,组合文件不会导致任何错误,因为组合脚本与10个非组合脚本相同,它们都以相同的方式加载(按顺序排列) ,从左到右,从上到下)。仔细检查你合并它们的方式。


Having read up recently on yahoo's web optimisation tips and using YSlow I've implemented a few of their ideas on one of my sites http://www.gwynfryncottages.com you can see the file here http://www.gwynfryncottages.com/js/gw-custom.js.

While this technique seems to work perfectly on most occasions, and really does speed up the site, but I do notice a significantly higher number of errors where the javascripts don't load or don't load completely while I'm working on the site so three questions:-

  • is combining scripts this way a good idea at all in terms of reliability?

  • is there any way to measure the number of errors i.e. the number of times the script failed to load?

  • is there any way to 'pre-load' the javascript or ensure that the number of loading errors is reduced?

解决方案

Of course it's good. You will not only decrease HTTP requests but you will cut down delays in downloading other resources.

Try using minify: http://code.google.com/p/minify/, I've been using it and I've no complaints.

I can assure you that combining files WON'T cause any errors as a combined script is the same as 10 non-combined scripts, they all load in the same way (In an ordered way, left to right, top to bottom). Double check the way you're combining them.

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

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