保持jQuery最新的实用方法? [英] Practical approach to keeping jQuery up to date?

查看:132
本文介绍了保持jQuery最新的实用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发的一些项目在jQuery 1.4.2或更早版本中有很强的根源,并且在缺乏最新版本的性能优势(或语法糖)之间,使用现在已弃用的方法的羞辱,以及部署一个3岁以上版本的积极维护的库的不舒服,现在迫在眉睫。

Some of the projects we're working on have strong roots in jQuery 1.4.2 or earlier, and somewhere between lacking the performance edge (or syntactic sugar) of the latest releases, the humiliation of using now-deprecated methods, and the discomfort of deploying a 3+ year old version of an actively maintained library, an upgrade is now imminent.

我们可以采用哪些社区流行的做法/重新访问以确保顺利推出(即关注不明显的兼容性问题,获取全局回归,重新考虑一些旧代码......)?它们如何最好地集成到SDLC中以便将来升级?什么是jQuery等库的合理升级时间表(我预计每次发布时都不会有显着的收益或合理的成本,但是每6-12个月一次可能是合理的)?

What are some practices popular in the community that we could adopt/re-visit to ensure a smooth rollout (i.e. focus on obscure compatibility issues, picking up global regressions, re-factoring some of the older code...)? How would they be best integrated into SDLC for future upgrades? What is a reasonable upgrade schedule for a library such as jQuery (I don't anticipate significant gains or justifyable costs to do so with every point release, but once every 6-12 months may very well be reasonable)?

推荐答案

要真正回答你的三个问题,这里有一些我已经完成或至少建议的事情:

To actually answer your three questions, here are some things I've done or at least recommend:

顺利升级推出的最佳做法


  • 进行测试。这些可以是JS和/或浏览器测试的单元测试。这些应该至少涵盖项目中使用的最典型和最复杂的功能。如果您没有测试,请编写它们。如果您不想编写测试,请重新考虑。如果你 reeeeally 不想编写测试,至少要有一个用户可以手动执行的用例列表。

  • 确保所有你的测试在升级之前通过。

  • 阅读您现在使用的版本与最新版本之间每个(主要)版本的发行说明。另请参阅已移除已弃用类别。如果您的任何代码使用jQuery UI,请查看这些发行说明并升级指南对于插页式版本。在执行此操作时,请记下您可能必须在代码库中更改的内容(可能大量使用 grep )。

  • 如果你的项目当前的jQuery版本> = 1.6.4,还要考虑使用 jQuery Migrate插件以进一步评估所需的工作。

  • 根据到达目的地所需的工作,确定您希望成为升级目标的版本,您的项目是否正在使用任何需要特定版本jQuery的第三方库,只有您可以考虑的其他因素等。

  • 与您的团队会面以查看更改列表完成您的代码库,并相应地划分/分配工作。也许写一些脚本或其他工具来帮助。如果您有,那么您的团队的编码风格指南/最佳实践文档可能也需要更新。决定一次性(推荐)或滚动更新版本,如果可能的话+可取的。想出一个合适的发布策略。 (我建议不要将升级作为代码库中另一个无关的大更改的一部分发布,因此如果需要,可以轻松回滚。)

  • 在整个升级过程中,不断运行测试。手动测试时,请始终监视浏览器控制台是否存在新错误。编写涵盖意外错误的新测试。

  • 当所有测试通过时,决定如何推出 - 如果它是一个站点,所有用户一次或一次百分比,对于图书馆或其他项目,也许你会发布一个测试版/前沿版本,你可以让更有野心的用户在野外为你测试。

  • 记录你的一切这样做会更容易下次。

  • [利润。]

  • Have tests. These can be unit tests for your JS and/or browser tests. These should cover at least the most typical and the most complex functionality used within your projects. If you don't have tests, write them. If you don't want to write tests, reconsider. If you reeeeally don't want to write tests, at least have a list of use cases that someone will be able to execute manually.
  • Make sure all your tests pass before the upgrade.
  • Read the release notes for every (major) version between the version you use now and the most current release. See also the Removed and Deprecated categories in the API docs. If any of your code uses jQuery UI, also look at those release notes and upgrade guides for the interstitial versions. As you do this, make note of the things you would likely have to change in your codebase (possibly making heavy use of grep).
  • If your project's current jQuery version is >= 1.6.4, also consider using the jQuery Migrate plugin to further assess the work required.
  • Decide on which version you want to be your upgrade target, based on the work required to get there, whether your project is using any third-party libraries that require a certain version of jQuery, other factors only you can consider, etc.
  • Meet with your team to go over the list of changes to be done to your codebase, and divide/assign the work accordingly. Maybe write some scripts or other tools to help out. If you have one, your team's coding style guide / best practices document may also need to be updated. Decide on one-shot (recommended) or rolling update releases, if that's possible+desirable. Come up with a suitable release strategy. (I recommend against releasing the upgrade as part of another unrelated large change to your codebase, so it's easy to roll back if you need to.)
  • Throughout the upgrade process, continually run your tests. When testing manually, always monitor the browser console for new errors. Write new tests that cover unexpected errors.
  • When all tests pass, decide on how you want to roll out--if it's a site, all users at once or a percentage at a time, etc. For a library or other project, maybe you'd release a beta/bleeding edge version that you can let your more ambitious users test out for you in the wild.
  • Document everything you just did so it will be easier for the next time.
  • [Profit.]

如何将升级整合到正常工作流程


  • 再次,测试。确保你拥有它们。确保它们很好,维护并覆盖了大部分代码库和用例。强烈建议使用持续集成设置来自动运行这些测试。

  • 考虑让您的团队创建并同意遵循编码样式指南或标准。这将使将来更容易搜索已弃用的函数调用或构造,因为每个人都会遵循类似的编码模式。诸如脚本,提交挂钩,静态分析工具等工具来强制执行或嗅出不良的编码风格可能很有用(取决于团队)。

  • 调查并决定使用包管理器,如 NPM bower 来管理jQuery版本和您可能使用的依赖它的其他第三方库。 (你仍然需要维护自己的JS代码并完成与上面相同的过程。)

  • 再次,一旦你超过1.6.4版本,请确保迁移插件是升级工作流程的一部分。

  • 评估从最初的大型升级过程起什么作用,什么不起作用,并从中提取最适合您当前工作流程的一般过程。无论您是否计划每次有新版本升级,都会有持续的维护任务和习惯,您可能希望将其作为一般开发最佳实践保留。

  • Again, tests. Make sure you have them. Make sure they're good, maintained, and cover a large portion of your codebase and use cases. A continuous integration setup to automate the running of these tests is highly recommended.
  • Consider getting your team to create and agree to follow a coding style guide or standard. This will make it easier in the future to search for deprecated function calls or constructs, since everyone would be following similar coding patterns. Tools such as scripts, commit hooks, static analysis utils, etc. to enforce good or sniff out bad coding style might be useful (depending on the team).
  • Investigate and maybe decide to use a package manager like NPM or bower to manage jQuery versions and other third party libraries you might use that depend on it. (You'll still need to maintain your own JS code and go through pretty much the same process as above.)
  • Again, once you're past version 1.6.4, make sure the Migrate plugin is part of your upgrade workflow.
  • Assess what worked from the initial big upgrade process, what didn't work, and extract a general process from this that works best with your current workflow. Whether or not you plan to upgrade every time there's a new version, there will be ongoing maintenance tasks and habits that you'd probably want to keep as general development best practices.

合理的升级时间表

这实际上是一个CBA /风险管理问题。你必须权衡一些事情:

That's essentially a CBA/risk management question. You'll have to weigh some things:


  • 在同一主要版本中没有破坏API的变化,所以你通常应该能够以最小的努力升级到最新的次要版本,不需要重构。这假设您已经拥有并维护了良好的测试,您可以在项目确定所有项目完成之前就可以在项目上运行。

  • 主要版本升级需要更多的研究,更多的重构,以及更多测试。在研究步骤之后,您应该对升级进行成本效益分析。

  • 这可能没什么关系,但是如果您的任何项目是一个拥有许多用户的网站,那将是什么制作所有用户的成本必须在下次访问时在网站上下载基本上所有已更改的JS文件(而不是坚持使用可能仍在其浏览器中缓存的旧版本)?

  • 升级的决定应始终是主观的。无论是次要还是重大,你每次都要证明升级是否值得。 请务必阅读发行说明。是否修复安全漏洞或与您或您的用户当前遇到的问题相关的错误?它是否会显着提高项目的性能(确保有基准来稍后验证)?它是否大大简化了您一直使用的编码模式,使您的代码更清晰,更容易编写?是否有您想要使用的第三方库依赖于这个较新的版本?您是否已使用哪些第三方库依赖于较旧的版本? (如果是这样,这些库是否可能很快升级以使用较新版本?)您是否对测试和QA流程有信心,升级将需要合理数量的开发资源并且不会导致重大回归?您是否考虑过最终还是用其他东西切换jQuery?等等。

  • There should be no breaking API changes within the same major version, so you should generally be able to upgrade to the most recent minor version with minimal effort, no refactoring required. This assumes you have and maintain good tests, which you can run on your projects before you decide that all is well enough for a rollout.
  • Major version upgrades require more research, more refactoring, and more testing. After the research step, you should do a cost-benefit analysis of upgrading.
  • This might not matter much, but if any of your projects is a website that has many users, what would be the cost of making all of your users have to download essentially all of the changed JS files on your site the next time they visit it (instead of sticking with the older versions that are probably still cached in their browsers)?
  • The decision to upgrade should always be a subjective one. Minor or major, you'll still have to justify each time whether any upgrade would be worth it. Always read the release notes. Does it fix a security vulnerability or a bug related to issues that you or your users are currently experiencing? Would it significantly improve the performance of your project (be sure to have benchmarks to verify it later)? Does it greatly simplify a coding pattern you've been using, allowing your code to be written more cleanly and easily? Is there a third-party library you want to use that is dependent on this newer version? Are there third-party libraries you already use which are dependent upon the older version? (If so, are these libraries likely to be upgraded anytime soon to work with the newer version?) Are you that confident in your tests and QA process that an upgrade will take a reasonable amount of development resources and cause no major regressions? Were you thinking of eventually switching out jQuery with something else anyway? Etc.

当然这只是我的建议。其中有一些反复出现的主题,我希望它们很清楚。无论如何,我希望有人觉得这很有用!

Of course this is just my advice. There are a few recurring themes in it, and I hope they are clear. In any case, I hope someone finds this helpful!

这篇关于保持jQuery最新的实用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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