问题描述
我在Google上搜索了很多,以寻找该问题的答案,但没有找到任何东西.
I googled quite a lot looking for the answer to this question but didn't find anything.
除了像yepnope这样的脚本加载器提供的其他功能之外,它是否还会比jQuery.getScript赋予我更好的性能和更好的缓存管理?
Aside of additionnal functionalities offered by a script loader like yepnope, is it going to give me better performance and better cache management than jQuery.getScript?
预先感谢
西蒙(Simon)
推荐答案
原则上,它们在功能上是相同的.从诸如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.
这篇关于jQuery.getScript与yepnope的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!