What is the difference between window.jQuery and if (type of jQuery == & ldquo; undefined & rdquo;) when resuming?


I want to load jQuery with a fallback solution and have come across two different solutions:


<script src="//ajax.googleapis.com/ [...] jquery.js"></script>
<script> window.jQuery || document.write('<script src="js/jquery.js"><\/script>') </script>


<script src="//ajax.googleapis.com/ [...] jquery.js"></script>
<script> if ( typeof jQuery == "undefined" ) document.write('<script src="js/jquery.js"><\/script>') </script>

What's the difference between these snippets and which solution would be the preferred one?

Both will perform the same action the only difference is that the former will execute faster than the latter.

That's why former is the preferred way.