重复的javascript和css包含 [英] Duplicate javascript and css includes

查看:148
本文介绍了重复的javascript和css包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于javascript包含和css包含的问题。如果不同开发人员两次使用相同的css或javascript文件,会发生什么情况?



http://example.com/sample.css



,并且如果再次包含相同的文件。



http://example.com/sample.css p>

我知道浏览器会缓存,不会产生后续的请求,但是会导致什么其他性能问题?

解决方案

重复的JavaScript和CSS文件通过创建不必要的HTTP请求(仅限IE)和浪费JavaScript执行(IE和Firefox)而损害性能。



在IE中,如果外部脚本包含两次并且不可缓存,则在加载页面期间会生成两个HTTP请求。即使脚本是可缓存的,当用户重新加载页面时也会发生额外的HTTP请求。



在IE和Firefox中,重复的JavaScript脚本会导致浪费时间多次评估同一个脚本。



无论脚本是否可缓存,都会执行此冗余脚本。






有关如何加快网站加载速度的详细信息,请参阅此非常好的文章



我已粘贴有关重复的JavaScript和CSS的信息,请参见上面的答案。


I have a question regarding the javascript includes and css includes. What happens if we included the same css or javascript files two times by different developers?

http://example.com/sample.css

and if the same file is included again..

http://example.com/sample.css

I know the browser will cache and doesn't make a subsequent request, but what other performance issues can it cause?

解决方案

Duplicate JavaScript and CSS files hurt performance by creating unnecessary HTTP requests (IE only) and wasted JavaScript execution (IE and Firefox).

In IE, if an external script is included twice and is not cacheable, it generates two HTTP requests during page loading. Even if the script is cacheable, extra HTTP requests occur when the user reloads the page.

In both IE and Firefox, duplicate JavaScript scripts cause wasted time evaluating the same scripts more than once.

This redundant script execution happens regardless of whether the script is cacheable.


For more information about how to make web site load faster, refer to this really good article.

I have pasted the info about duplicate JavaScript and CSS, here in the answer above.

这篇关于重复的javascript和css包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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