CodeSOD: Load, Load, Load your Deps

It's not uncommon for web applications to fetch key dependencies from remote, public CDNs. Why host Angular or jQuery yourself, when Google will do it for you? That, at least, was part of the logic underpinning this old code Dan found.

<script src="//"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<script src="js/jquery.js"></script>

First, we fetch the jQuery 1.9.1 library from Google. Then, we add another script, and check: if window.jQuery is defined, great- but if not, we load a local version of the 1.9.1 jQuery library. Then… we unconditionally load an unversion-tagged version of the jQuery library.

"I like a dev who double-checks everything," Dan writes. "Even triple-checks are fine."

There's just one note on those triple-checks, Dan notes.

But here's the first line of the "js/jquery.js" file:
/*! jQuery v@1.8.0 | */

[Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published. Required fields are marked *