jQuery.getScript vs yepnope performance

别说谁变了你拦得住时间么 提交于 2019-12-12 06:36:25

问题


I googled quite a lot looking for the answer to this question but didn't find anything.

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?

Thanks in advance,

Simon


回答1:


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.

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.

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.




回答2:


You can also use head.js if you are loading multiple JS files.



来源:https://stackoverflow.com/questions/6468678/jquery-getscript-vs-yepnope-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!