javascript 为什么 facebook 不使用 jQuery(或类似的)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5445232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why doesn't facebook use jQuery (or similar)?
提问by dynamic
Facebook is heavily JavaScript based. Why doesn't it rely on jQuery (or any other similar library)?
Facebook 在很大程度上基于 JavaScript。为什么它不依赖于 jQuery(或任何其他类似的库)?
Edit: Why close this question? this isn't subjective. facebook doesn't use jQuery (or any other framework) for a reason, that i am asking for.
编辑:为什么关闭这个问题?这不是主观的。facebook 不使用 jQuery(或任何其他框架)是出于我要求的原因。
回答by selbie
Short answer: You'll have to ask the Facebook development team.
简短回答:您必须询问 Facebook 开发团队。
Best guesses:
最佳猜测:
Large companies with large software products (and mature code bases) tend to stick with what works - even when there is a popular framework already out there that is compelling to move to. Remember, Facebook was around long before JQuery was considered standard.
They likely will be supporting their existing code for many more years to come. And the benefit to cost ratio of making a "switch" to a new language or framework may be too low to warrant a re-write or a transition. Case in point: Sun didn't port much of Solaris to Java. Only a marginal amount of Windows is written in C#.
In the year 2011when I first wrote this: if you actually look at Facebook's website, their DOM structure isn't that complex. They don't have very many animations. They aren't a very heavy AJAX site. Given that, JQuery may not be compelling for them. Update - In 2015: FB is much more dynamic than it was years ago. So #3 here doesn't hold the same weight as it did in 2011.
Also, when you have multiple teams contributing to a single software product (or web site), it's important that everyone standardize on the same framework. If every team integrated with a different framework, then the code becomes bloated quickly with linkage of all these different libraries. In the case of a website, this means longer page load times.
JQuery is designed to support the largest set of browsers. In some cases, this might mean "optimizing for the lowest common denominator". FB may want to take advantage of newer browser features when available.
FB may not want to get too "locked in" to JQuery. JQuery was known to have a few bugs with some of the newer browsers that were in beta. Now if Facebook has a million lines of code based on JQuery 1.6, it might be buggy when run on IE 10, FF 5, and Chrome 12 near year. To make this work, they would have to upgrade to JQuery 1.7, but that means a huge amount of testing across their entire code base.
Finally, they may have something internal that works better than JQuery. I would not be surprised if Facebook already has a server-side framework that outputs HTML+JS based on the browser making the page request.
拥有大型软件产品(和成熟的代码库)的大公司倾向于坚持使用有效的方法 - 即使已经有一个流行的框架令人信服。请记住,早在 JQuery 被视为标准之前,Facebook 就已经存在了。
他们可能会在未来很多年支持他们现有的代码。并且“切换”到新语言或框架的收益与成本比可能太低而无法保证重写或转换。举个例子:Sun 并没有将很多 Solaris 移植到 Java。只有少量的 Windows 是用 C# 编写的。
在 2011年我第一次写这篇文章的时候:如果你真的看看 Facebook 的网站,他们的 DOM 结构并没有那么复杂。他们没有很多动画。它们不是一个非常繁重的 AJAX 站点。鉴于此,JQuery 可能对他们没有吸引力。 更新 - 2015 年:FB 比几年前更有活力。所以这里的#3 与 2011 年的权重不同。
此外,当您有多个团队为单个软件产品(或网站)做出贡献时,每个人都在同一个框架上进行标准化很重要。如果每个团队都集成了不同的框架,那么由于链接所有这些不同的库,代码会很快变得臃肿。对于网站,这意味着更长的页面加载时间。
JQuery 旨在支持最大的浏览器集。在某些情况下,这可能意味着“针对最小公分母进行优化”。FB 可能希望在可用时利用较新的浏览器功能。
FB 可能不想被 JQuery 太“锁定”。众所周知,JQuery 在一些处于测试阶段的较新浏览器中存在一些错误。现在,如果 Facebook 有 100 万行基于 JQuery 1.6 的代码,那么在 IE 10、FF 5 和 Chrome 12 上运行时可能会出现问题。为了使这项工作成功,他们必须升级到 JQuery 1.7,但这意味着要对整个代码库进行大量测试。
最后,他们可能有一些比 JQuery 更有效的内部功能。如果 Facebook 已经有一个服务器端框架,可以根据发出页面请求的浏览器输出 HTML+JS,我不会感到惊讶。
I recognize that none of these answers are very popular. What developer on your team doesn't want to switch to the latest and greatest technology? But when you think about the business case and cost of supporting a framework relative to the size of your business, you have to tread carefully.
我认识到这些答案都不是很受欢迎。您团队中的哪个开发人员不想切换到最新最好的技术?但是,当您考虑与业务规模相关的业务案例和支持框架的成本时,您必须谨慎行事。
回答by Jared Farrish
Because they choose to do their own thing?
因为他们选择做自己的事?
回答by Mike Lewis
Facebook doesn't rely on libraries for the exact reason you stated, it is heavily javascript based. Because of this, they want full control and customization of the code that they write. This is so they can write solutions that are specific to their applications, which also allow for efficiency. Efficiency is a huge thing for all sites (and most definitely Facebook) and this way they can easily edit their code easily to perform to their likings.
Facebook 不依赖于您所说的确切原因的库,它很大程度上基于 javascript。因此,他们希望完全控制和自定义他们编写的代码。这样他们就可以编写特定于他们的应用程序的解决方案,这也提高了效率。效率对所有网站(尤其是 Facebook)来说都是一件大事,这样他们就可以轻松地编辑他们的代码以按照自己的喜好轻松执行。
回答by Dejan Marjanovic
Because they build what they need on their own, jQuery is also Javascript.
因为他们自己构建他们需要的东西,jQuery 也是 Javascript。
回答by dynamic
If you want my opinion:
如果你想要我的意见:
I think the only reason is because Facebook was out in 2003/2004, jQuery in 2006. At that point was too late to reconvert all js to jQuery
我认为唯一的原因是因为 Facebook 于 2003/2004 年推出,jQuery 于 2006 年推出。那时已经太晚了,无法将所有 js 重新转换为 jQuery
回答by Crayon Violent
In my personal experience its because a lot of big companies feel they are too good to use frameworks, they feel the need to keep everything "in-house"
以我个人的经验,这是因为很多大公司觉得他们太擅长使用框架了,他们觉得有必要将所有东西都保留在“内部”
回答by Ben
They require such a high degree of performance and efficiency that jQuery wont cut it. They need an api that suits solely their needs with no extra unused code or features.
它们需要如此高的性能和效率,jQuery 不会削减它。他们需要一个完全满足他们需求的 api,没有额外的未使用代码或功能。
回答by stealthyninja
@yes123: When you build a website that ends up serving half the planet, you will start running into the walls which frameworks of any kind tend to end up imposing. When you make your own custom frameworks, database querying languages, etc., you have a lot more control and can really get down to the business of optimising a site that has to serve extreme amounts of requests per second.
@yes123:当您建立一个最终服务于地球一半的网站时,您将开始遇到任何类型的框架最终都会强加的墙。当您制作自己的自定义框架、数据库查询语言等时,您将拥有更多的控制权,并且可以真正着手优化一个每秒必须处理大量请求的站点。
There are of course other considerations as well, if everything you work on is open source and publicly available, so are the bugs and inherent weaknesses. Not everyone is so altruistic to submit a fix to the original authors of a framework or library; some would use it to exploit. If your source is essentially closed and proprietary, it makes the task of malicious users that much more tricky.
当然还有其他考虑因素,如果您所做的一切都是开源且公开可用的,那么错误和固有弱点也是如此。并非每个人都如此无私地向框架或库的原始作者提交修复程序;有些人会用它来剥削。如果您的来源本质上是封闭的和专有的,那么恶意用户的任务就会变得更加棘手。
In any event, this isn't really a question for StackOverflow...
无论如何,这对于 StackOverflow 来说并不是一个真正的问题......