Yesterday Twitter went nuts over a little site called “You Might Not Need jQuery”. The site’s seemingly innocent claim was that many things that you think you need jQuery for are actually not so bad in plain old JavaScript, depending on what browsers you are supporting.

昨天,Twitter在一个名为“您可能不需要jQuery”的小网站上发疯了。 该网站看似无辜的说法是,您认为需要jQuery的许多东西实际上在普通的旧JavaScript中并不是那么糟糕,这取决于您所支持的浏览器。

jQuery and its cousins are great, and by all means use them if it makes it easier to develop your application.

jQuery及其表亲非常出色,如果可以简化应用程序的开发,请务必使用它们。

If you’re developing a library on the other hand, please take a moment to consider if you actually need jQuery as a dependency. Maybe you can include a few lines of utility code, and forgo the requirement.

另一方面,如果您正在开发库,请花一点时间考虑是否确实需要jQuery作为依赖项。 也许您可以包括几行实用程序代码,然后放弃要求。

It then proceeded to provide example code—what a line of jQuery was compared to the vanilla JavaScript alternative. Not all of these snippets were exactly identical to the jQuery code in terms of what they accomplished, but they were pretty close.

然后,它继续提供示例代码-将jQuery的行与普通JavaScript替代项进行了比较。 就它们完成的功能而言,并非所有这些代码片段都与jQuery代码完全相同,但是它们非常接近。

The site itself didn’t seem particularly exciting or controversial. We’ve seen these sorts of comparison before, and frankly claiming that you “might” not need jQuery is an awful innocent statement to make.

该网站本身似乎并不特别令人兴奋或引起争议。 我们之前已经看过这种比较,并且坦率地声称您“可能”不需要jQuery是一个可怕的无辜声明。

But the reaction was more divided than I expected with many getting a little worked up about the site. Which of course causes me to wonder—if suggesting we “might” not need a technology can cause such a heated discussion, perhaps we “might” be just a little too attached to it.

但是React比我预期的要分散得多,许多人对该站点进行了一些处理。 当然,哪一个使我感到怀疑-如果暗示我们“可能”不需要某种技术会引起如此激烈的讨论,也许我们“可能”对此有点依附。

It’s not that I don’t like or use libraries and frameworks. I do. In fact, I use tools like jQuery and Ender quite frequently. A good library brings the benefit of being well-tested, documented (well, in some cases at least) and can be very helpful for complex functionality or when working in a team environment.

不是我不喜欢或使用库和框架。 我做。 实际上,我经常使用jQuery和Ender之类的工具。 一个好的库带来了经过良好测试,记录(至少在某些情况下还可以)的好处,并且对于复杂的功能或在团队环境中工作非常有帮助。

What worries me is that for many, libraries have become the default. They’re rolled into boilerplates and pattern libraries as an assumed dependency. And if we know anything about default settings, it’s that most people will stick with them. This undoubtedly leads to many projects incurring this overhead without every giving consideration to whether it is really necessary.

让我担心的是,对于许多人来说,库已成为默认库。 将它们作为假定的依赖关系卷入样板和模式库。 如果我们对默认设置一无所知,那就是大多数人都会坚持使用它们 。 无疑,这导致许多项目产生了这种开销,而没有全盘考虑是否确实必要。

According to the the latest run of HTTPArchive’s top 1000 sites (January 15, 2014), the average weight for a page is 1463kb. Scripts weigh in at 272kb, second only to images in total weight. Mobile tells a similar story. The average site on a mobile device weighs in at 717kb, of which 168kb is JavaScript.

根据最新的HTTPArchive前1000个站点的运行情况(2014年1月15日),页面的平均权重为1463kb。 脚本的总重为272kb,仅次于图像。 Mobile讲述了一个类似的故事。 移动设备上的平均站点重717kb,其中168kb是JavaScript。

Compare those numbers to the start of the year and we see an alarming trend. Script weight is up 28% from the start of the year on desktop pages and up 22% on mobile.

将这些数字与年初进行比较,我们会看到一个惊人的趋势。 与年初相比,台式机页面的脚本权重增加了28%,移动设备的脚本权重增加了22%。

This is concerning, but it’s not just download sizes that you should be worried about. In a presentation given at Velocity in 2011, Maximiliano Firtman pointed out that on some phones (older, but still popular, BlackBerry devices for example) can take up to 8 seconds just to parse jQuery. More recent research from Stoyan Stefanov revealed that even on iOS 5.1, it was taking as many as 200-300ms to parse jQuery.

这很重要,但您不仅要担心下载大小。 在2011年Velocity上的一次演讲中, Maximiliano Firtman指出 ,在某些手机(例如较旧但仍很流行的BlackBerry设备)上, 解析 jQuery最多可能需要8秒钟。 Stoyan Stefanov的最新研究表明,即使在iOS 5.1上,解析jQuery也要花费200-300ms的时间。

This isn’t even the worst case scenario. I’ve worked on projects where some of the devices we needed to test on couldn’t load the page at all if jQuery was present—it was just too much JavaScript for the device to handle.

这甚至不是最坏的情况。 我参与的项目中,如果存在jQuery,我们需要测试的某些设备根本无法加载页面-对于该设备而言,JavaScript太多了。

Performance is not the only concern. At times, the abstraction that libraries and frameworks provide can actually be harmful. Without an understanding of the underlying language in use, it can confuse developers as much as it aides them.

性能不是唯一的问题。 有时,库和框架提供的抽象实际上可能是有害的 。 如果不了解所使用的基础语言,那么它会给开发人员带来极大的困惑,同时也会给开发人员带来很大的帮助。

I’m know I’m picking on jQuery, but that’s primarily because of its un-paralleled popularity. My concerns with starting with a library as a default method of coding are not confined to any one library in particular.

我知道我选择了jQuery,但这主要是因为它无与伦比的受欢迎程度。 我对以库作为默认编码方法的关注并不特别局限于任何一个库。

It seems this is a tricky topic to approach because it is so often viewed as being black or white: you’re either against frameworks or you’re opposed to them. Like so many topics, people can get religious about this stuff. But it’s not about what is the right™ way to do it: it’s about using the best tool for the job and arming yourself with the knowledge necessary to make that determination.

似乎这是一个棘手的话题,因为它经常被视为黑色或白色:您要么反对框架,要么反对框架。 像许多主题一样,人们可以对此宗教产生兴趣。 但是,这与正确的™方法无关;而在于使用最佳工具完成工作,并为自己提供必要的知识以做出决定。

The reality is that you don’t always need to use a framework or library. Often times, you can get by with just a little bit of native JavaScript, saving precious bytes and seconds while doing so. When the job calls for frameworks, then use a framework (and do so responsibly). When you can do it just as well with vanilla JavaScript, then roll your own. (For anyone thinking about commenting “Don’t worry about it, just include one less image on your site” response, I’m going to preemptively respond: why not do both? One less image is not an excuse for not being careful about JS size.)

现实情况是,您并不总是需要使用框架或库。 通常,您只需要一点点本机JavaScript,就可以节省宝贵的字节和秒数。 当工作需要框架时,请使用框架( 并负责任地使用 )。 当您可以使用普通JavaScript很好地做到这一点时,然后自己动手制作。 (对于任何想评论“不用担心,只在您的网站上少添加一张图片”评论的人,我都会先发制人地做出回应:为什么不同时做这两个呢?少一张图片不是您不小心的借口JS大小。)

Everything has a cost associated with it. Whenever we add something to our sites we need to be able to think critically about whether or not the value outweighs the cost. JavaScript libraries are no exception.

一切都有相关的成本。 每当我们在网站上添加内容时,我们都需要能够认真思考价值是否超过成本。 JavaScript库也不例外。

I’m not saying that we stop using libraries altogether—and neither were the people who created “You Might Not Need jQuery”. I’m suggesting we make that decision with a great deal of care.

我并不是说我们完全停止使用库,而创建“您可能不需要jQuery”的人也没有。 我建议我们在做出这个决定时要格外小心。

翻译自: https://timkadlec.com/2014/01/smart-defaults-on-libraries-and-frameworks/

智能默认值:关于库和框架相关推荐

  1. 如何使用智能默认值来减少认知负担

    作者:Nick Babich 翻译 :吴祺深 欢迎访问网易云社区,了解更多网易技术产品运营经验. 如果你问UX设计师们他们的工作目标是什么,他们可能会说,他们的目标是让用户的生活变得简便.当用户体验设 ...

  2. lua 函数 默认值_Unity热更新框架之xLua

    一:xLua概述 二:Lua文件加载 三:xLua文件配置 四:Lua与C#交互 五:xLua热更新 一:xLua概述 1.1 xLua简介 xLua是由腾讯维护的一个开源项目,xLua为Unity. ...

  3. python mysql 的默认值_python--MySQL 库,表的详细操作

    一 库操作 数据库命名规则 可以由数字,字母,下划线,@, #, $ 区分大小写 唯一性 不能使用关键字如 create  select 不能单独使用数字 最长128位 # 这些是对上次的补充. 二 ...

  4. ajax默认什么方法,ajax设置默认值ajaxSetup()方法

    $(function(){ //设置全局 jQuery Ajax全局参数 $.ajaxSetup({ type:"POST", async:false, cache:false, ...

  5. go基础库之环境变量的获取与设置以及如何使用默认值

    golang 基础库之 go 获取命令行参数,介绍了环境变量的获取与设置以及如何使用默认值 环境变量的获取与设置以及如何使用默认值 Golang 版本 1.12.1 前言 环境变量作为配置选项可以显著 ...

  6. MySQL默认库可以删_个人总结:Sql(一:创建删除修改库表||附:mysql数据类型及默认值)...

    个人总结:Sql(一:创建&删除&修改库&表||附:mysql数据类型及默认值)createdatabasecreate tablealterdatabasealtertabl ...

  7. vue中$event理解和框架中在包含默认值外传参

    在vue中普通方法中默认带有event DOM事件如greet方法,如果是内联函数的话如warn方法,只需要在定义方法的地方同时传入$event即可,这里需要强调的是在iview中,这里用的是sele ...

  8. yii框架的下拉框多选,设置默认值等(dropDownList)

    一.前言 根据需求,需要更改下拉框为多选框.本来以为只是很简单的东西,但是实际修改起来却碰到不少bug,多选框无法选中,给多选框赋默认值等.这里记录一下 二.修改单选下拉框为多选下拉框 echo $f ...

  9. mysql+默认值+default_十六、MySQL 中数据类型的默认值 - default 约束-搜云库

    MySQL 中,所有的数据类型,都可以显式或隐式的拥有默认值. 我们可以使用 DEFAULT 约束显式的为列指定一个默认值.比如 CREATE TABLE t1 ( i INT DEFAULT -1, ...

最新文章

  1. Path HDU6582
  2. 【怎样写代码】复杂对象的组装与创建 -- 建造者模式(五):关于Director的进一步讨论
  3. 寻找调用DebugPort的函数
  4. 【开发环境】Windows 中安装 Python 各个版本 ( 下载 Python 各版本 SDK | 安装 Python )
  5. USB有时adb shell连不上设备
  6. MyEclipse使用总结——设置MyEclipse开发项目时使用的JDK
  7. html5与其他语言的优势,浅谈:html5和html的区别
  8. IOC控制反转(依赖注入思想)
  9. mysql 忘记密码处理方式
  10. 凸优化第四章凸优化问题 4.6 广义不等式约束
  11. MySQL中删除表中并不存在的数据不报错
  12. IO编程——文件复制操作
  13. WS2811彩带驱动库函数
  14. 视频教程-HTML零基础经典入门视频-HTML5/CSS
  15. 苹果cms(maccms) player播放器解密
  16. web app 中如何调用支付宝app 进行支付
  17. QTableWidget实现复制粘贴
  18. 人民币金额(数字)大写转换及金币单位切换
  19. php中关于冬夏时令切换引发的问题
  20. 保研之旅7:成电“信息与通信工程学科”夏令营

热门文章

  1. ros小车控制学习-------控制真实机器人做圆周运动
  2. STM32CubeIDE、HAL、OLED、MPU6050学习笔记
  3. 战地1服务器列表显示实际ping,《战地1》如何在游戏中随时查看网络质量 怎么调处网络效能表...
  4. linux 2.6.30 内核编译 提示 ‘make[1]: *** [arch/x86/vdso/vdso.so.dbg] Error 1’ 错误
  5. 煜辰his系统(sql DB)
  6. 设计模式与3D游戏编程
  7. 【计算机网络】【链路层和局域网-1】
  8. 硬盘录像机接入EasyNVR花屏问题的解决办法
  9. 用java的robot类以及Gui 制作一个游戏(阴阳师)脚本
  10. Microsoft Excel 教程:如何在 Excel 中进行数学运算?