为什么 jQuery 没有集成在浏览器中 [英] Why is jQuery not integrated within the browser

查看:18
本文介绍了为什么 jQuery 没有集成在浏览器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么不将 jQuery 集成到浏览器中,因此无需在您的网站上引用它,相反,浏览器只会注意到使用的 jQuery,并且一切正常.

Why isn't jQuery intergrated into browsers, so there would be no need to have to reference it on your site, and instead, the browser just notices the jQuery used, and everything works fine.

尽管引用 jQuery 并不难,但它仍然是一个非常酷的特性.谢谢.

Even though referencing jQuery isn't that difficult, it stil would be a very cool feature to have. Thanks.

推荐答案

在外部脚本中使用 jQuery 的主要优点是您可以在新版本的 jQuery 中获得新功能,并且(假设 jQuery 执行了正确的跨浏览器支持),您可以自动在您的观众使用的所有浏览器中使用该功能.您可以对您的网站进行编码以使用新的 jQuery 功能,并且知道它可以在所有常用浏览器中运行.

THE main advantage of having jQuery in an external script is that you can obtain a new feature in a new version of jQuery and (assuming jQuery did proper cross-browser support), you can automatically have that feature available in all the browsers your viewers use. You can code your site to use that new jQuery feature and know that it will work in all browsers in common use.

如果浏览器中内置了 jQuery 功能,那么您将不得不使用最小公分母方法.您可以依赖的功能不会超过您想要与之兼容的最落后的浏览器或最旧的浏览器中的功能.当引入新功能时,您必须等待近十年,直到所有不支持该新功能的旧浏览器退出普遍使用,然后才能确定它是否可以安全使用.或者,您必须为它构建自己的跨浏览器支持,从而创建一个新的类似 jQuery 的跨浏览器库,循环将重新开始.

If jQuery functionality was built into the browser, you'd be stuck with a least common denominator approach. You could rely on no more features than were in the most backward browser or oldest browser that you wanted to be compatible with. When a new feature was introduced, you'd have to wait nearly a decade for all older browsers that don't support that new feature to drop out of common use before you could be sure it was safe to use. Or, you'd have to build your own cross-browser support for it, thus creating a new jQuery-like cross-browser library and the circle would start over again.

使用 jQuery,您只需在您的网站中包含最新版本的库,您就可以在所有常见浏览器中自动使用该新功能.

With jQuery, you just include the newest version of the library in your site and you can automatically use that new feature in all common browsers.

至于效率,将 jQuery 包含为外部文件并不会损失太多,只要它做得正确.如果您使用更常见的 CDN 之一(如 Google)链接到 jQuery,那么 jQuery 可能已经在浏览器缓存中,并且它是从本地硬盘加载的,而不是每次需要时都下载.是的,如果它是内置的,它可以进一步优化,但是你会失去之前谈到的所有好处,这首先否定了拥有它的全部原因.

As for efficiency, you aren't losing much by including jQuery as an external file is it is done properly. If you use one of the more common CDNs (like Google) to link to jQuery, then jQuery is probably already in the browser cache and it's loaded from local hard disk rather than downloaded each time it's needed. Yes, it could be optimized further if it was built in, but then you lose all those benefits talked about earlier which negates the whole reason for having it in the first place.

此外,内置功能并不是每年都在进步.他们是.它被称为标准运动.问题是它移动得非常缓慢.看看 CSS3 过渡.我们今天在所有流行版本的 Firefox、Chrome、Opera 和 Safari 中都支持 CSS3 过渡,但还没有在任何版本的 IE 中.因此,由于我们距离 IE7、IE8 和 IE9 的所有流行使用消失还有很长的路要走,我们距离能够使用"CSS3 并期望浏览器支持它还有很长的路要走.仍然需要一个动画库.即使 IE10 明天发布并自动支持所有 CSS3 转换,我们仍然需要很多年才能停止在网络上使用所有旧版本的 IE.

Also, it's not like the built-in capabilities aren't moving forward every year. They are. It's called the standards movement. The issue is that it moves very slowly. Look at CSS3 transitions. We have CSS3 transition support today in all popular versions of Firefox, Chrome, Opera and Safari, but not in any version of IE yet. So, since we're still a long ways from all popular use of IE7, IE8 and IE9 disappearing, we're a long ways from being able to just "use" CSS3 and expect the browser to support it. An animation library is still needed. Even if IE10 shipped tomorrow and automatically supported all of CSS3 transitions, we'd still be many years away from when all older versions of IE stopped being used on the web.

这篇关于为什么 jQuery 没有集成在浏览器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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