且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery.getScript与yepnope的性能

更新时间:2023-12-04 22:12:16

原则上,它们在功能上是相同的.从诸如yepnope之类的东西中获得的最大收益是集成条件加载.而使用$ .getScript,则必须手动执行任何必要的布尔检查.几乎没有什么事情像测试已经支持yepnope这样的事实,但是如果您希望在自定义条件加载代码中具有相同的确定性,则必须编写自己的条件.

In principle, their functionally the same. The biggest gain you get from something like yepnope is integrated conditional loading. Whereas, with $.getScript, you'd have to do any requisite boolean checks manually. There's also little things like the fact that yepnope is already supported by tests, whereas if you wanted the same certainty in your custom conditional-loading code, you'd have to write your own.

简而言之,yepnope只是一个时间节省者,就像jQuery本身是一个时间节省者一样.在jQuery中,您无法做的事情在普通JavaScript中无法实现.这只需要更多的时间,精力和精力.如果您正在考虑动态加载脚本,我建议您为此使用一个库,而不是重新发明***.

In short, yepnope is just a time-saver like jQuery itself is a time-saver. There's nothing you can do in jQuery that you can't do in vanilla JavaScript; it just takes more time, energy, and effort. If you're thinking about dynamically loading scripts, I would recommend that you use a library for that, instead of re-inventing the wheel.

有趣的是,yepnope实际上捆绑在Modernizr中(我不知道).因此,如果您打算开始使用HTML5,则可以包含Modernizr并获得您的shiv,功能感知功能和动态脚本加载功能.

Interestingly, yepnope is actually bundled into Modernizr (I didn't know that). So, if you're looking to start getting into HTML5, you can include Modernizr and get your shivs, feature-sensing sugar, and dynamic script loading all in one.