jQuery with ASP.NET

Building rich UI with jQuery and ASP.NET

How to Check If jQuery Plugin is Loaded

with one comment

A few days ago I was playing with jQuery plugin jTemplates. I had a tough time trying to get it working. As usual in such situation you can’t see obvious mistakes and instead you keep exploring all options which can possibly go wrong. During one of such exploration I was checking if  jTemplates has been correctly loaded. Of course real problem was completely different…  :)

But still, the code checking if plugin is loaded is very simple and thanks to it you have one less option to worry about. Here it is:

//check if jTemplates is loaded
if (!jQuery.fn.processTemplate) {
    alert("jTemplates is not loaded");
    return;
}

jTemplate has a function called processTemplate. If entire plugin was loaded correctly then this function is available. And this is exactly what is checked within if() statement. If for some reason plugin wasn’t loaded user will get an information: “jTemplates in not loaded”.

Of course you should use more user-friendly messages or deal with such problems in more elegant way. But nevertheless, checking if plugins are loaded should be a mandatory step for all developers. It doesn’t cost you much but in rare (hopefully) situations your site won’t crash because of lack of plugin which you expect to be loaded.

VN:F [1.9.20_1166]
Rating: 10.0/10 (1 vote cast)
How to Check If jQuery Plugin is Loaded, 10.0 out of 10 based on 1 rating

Written by admin

November 9th, 2010 at 1:44 pm

One Response to 'How to Check If jQuery Plugin is Loaded'

Subscribe to comments with RSS or TrackBack to 'How to Check If jQuery Plugin is Loaded'.

  1. Thank you very much …… great keep going

    VA:F [1.9.20_1166]
    Rating: 0.0/5 (0 votes cast)

    Saeed7

    15 Feb 12 at 7:59 am

Leave a Reply