X

LATEST #JQUERY NEWS

Quick Tip: How to Load jQuery Conditionally


Many developers like to link to an externally hosted jQuery library, like for example Google’s jQuery library (http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js), but the problem with linking to an external jQuery library is that they can be a bit unreliable. If for some reason there are any issues with the server, the script may not be able to be accessed and your jQuery code won’t work.

HTML5’s boilerplate¬†uses a really cool conditional statement that will load a local jQuery library on the occasion that, for whatever reason, your external library isn’t loading or working correctly. Check it out:

<!-- Grab Google CDN jQuery. fall back to local if necessary -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
   window.jQuery && document.write('<script src="js/jquery-1.4.2.min.js"><\/script>')
</script>

Of course, you’ll need to insert your own path to wherever your local jQuery files are located (instead of ‘<script src=”js/jquery-1.4.2.min.js”></script>’), but this is a very simple way to make sure that your jQuery library always loads.

Recently Published

article image
»

7 Responsive jQuery Dropdown Menu Plugins

Dropdown Menu Plugins Dropdown menus are mostly used for website ...

article image
»

20 Stylish and Modern jQuery Tooltip Plugins

jQuery Tooltip Plugins Tooltips are a great option for showing extra ...

article image
»

15 Newest jQuery plugins for responsive website

Due to the proliferation of smartphones and tablets, responsive ...

article image
»

How to use Redux with jQuery

State management is one of most integral parts of any software and a ...

article image
»

Fade HTML Table Row on Hover Using jQuery

HTML tables are the ideal choice for displaying data in tabular form. ...

article image
»

Drag and Drop HTML Table Rows Using jQuery

HTML tables are the preferred UI option for displaying data. Sorting, ...

article image
»

Top 5 Best JavaScript Template Engines

Template engines help in the decoupling of HTML and JavaScript code ...

article image
»

3 jQuery/JavaScript Plugins for Push Notifications

Push notifications started from the mobile business but this ...

article image
»

Create Smooth Animation Using jQuery’s “stop()”

Making Quick Work jQuery’s animate() method is a quick way to ...