How does HTML5 Boilerplate jQuery library fallback work?

家住魔仙堡 提交于 2019-12-01 13:23:25

The || is the if statement in this case. If window.jQuery returns TRUE, then anything after the or statement (||) won't get loaded. If it's FALSE, then it'll continue on to load jquery.

Edit: Just to clarify a bit. If you do if (var1 && var2) in javascript, it'll evaluate BOTH variables to check if they're both true. If you make it if (var1 || var2), then if the first variable evaluates to TRUE, there's no need to evaluate the rest of the expression, since it'll automatically be true either way.

In this case, that's exactly what your code is doing. If window.jQuery is FALSE (meaning jQuery wasn't loaded), then continue on and evaluate the next expression--which in this case loads the jquery from a local file. It's just not wrapped in an IF statement since it's not necessary.

If jQuery file from google CDN or anywhere is loaded, it would have been added a property jQuery to window object. Second line of your script checks if window.jQuery is defined or not, if not it executes the other part of || statement which adds a script tag having local jQuery file location src attribute to load it.

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