The Mighty Blog

Apr28

Written by:Will
4/28/2009  RssIcon

Some twitter conversations today led me to see the need for a jQuery tips blog entry to help DotNetNuke developers integrate jQuery into their modules easier.  There are a handful of things that can easily stumble someone new to the jQuery scene.

  1. Make sure you call jQuery.noConflict();.  This is necessary to not cause other client scripts and libraries to run errors.  This is due to the fact that other client scripts might be using the $ designator for a JavaScript class. [jQuery.noConflict(); documentation]
  2. If manually adding jQuery, try to load the jQuery library in the header before all others.  Not doing this can lead to the jQuery library not being loaded before another client script or library tries to use it.  This is especially true of jQuery plugins.
  3. Always call the jQuery core methods using the jQuery() format.  This is related to the previous issue.
  4. Check the jQuery plugin source code.  Not all jQuery plugins use the long form of calling jQuery.  This can result in errors if you have called jQuery.noConflict();.
  5. In DNN 5+, register jQuery.  DNN 5+ allows module developers to register jQuery to be loaded only when modules need it.  Just call DotNetNuke.Framework.jQuery.RequestRegistration().  This prevent jQuery from being loaded when it’s not used.  If your skin is using widgets, this is not necessary, but should be done for commercial modules regardless.
  6. Use the jQuery hosted option.  Look in the Host Settings (DNN 5).  This is not necessary, but can reduce page load times, since the site visitor may already have the library loaded in case.  However, if the hosted source is having problems hosting the library, your page load times could increase dramatically, as well as not load the library at all.  Either way, your client side-code will break.
    Host > Host Settings > jQuery Settings > Use Hosted jQuery Version
  7. Only use jQuery Debug Version for debugging.  Look in Host Settings (DNN 5).  By default, DNN loads the jquery.min.js file.  However, when you are debugging jQuery, this makes it nearly impossible to debug.  Check this setting to tell DNN to load the uncompressed version of the jQuery library.  Only do this on development machines, if possible.
    Host > Host Settings > jQuery Settings > Use jQuery Debug Version
  8. Wrap onload scripts in a ready() function.  Wrapping your scripts in the ready() function prevents conflicts with other scripts on the page, including Microsoft scripts, and the DNN Client API.

Beyond the above tips, your your typical JavaScript debugging methods will apply.  I hope this helps.

Technorati Tags: ,,,

6 comment(s) so far...


Gravatar

Great post! Thanks for your help Will

By Gaz on   4/29/2009
Gravatar

Great tips Will. Thanks.

Dax

By Dax Davis on   4/29/2009
Gravatar

Good tips thanks for those

By Dylan Barber on   4/29/2009
Gravatar

It is of course my pleasure. I am happy to help. :)

By Will on   4/29/2009
Gravatar

I forgot another tip... Consider this line item #8:

8. Any script that needs to be run at page load, wrap inside of a ready function. This prevents any conflicts from happening either with the Microsoft scripts, or the DNN Client API.

jQuery(document).ready(
function() {
/* your code here */
}
);

By Will on   5/5/2009
Gravatar

Great tips, thanks for the help.

By Surge on   7/10/2010

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Add to Technorati Favorites
Tweet about my blog
Will Strohl - The Mighty Blog - RSS Feed

Tag Cloud

Sort by:Tag | SizeRSS
camp   community   dnn   dotnetnuke   dotnetnuke®   event   example   free   get   group   integer   jquery   meeting   module   odug   orlando   search   session   think   use  
The opinions expressed here are the personal opinions of Will Strohl and do not necessarily represent the views and opinions of the DotNetNuke Corporation.
© Copyright 2004-2010 by Will Strohl. All rights reserved.Website Skinned By: Ralph Williams  Website Hosted By: Applied Innovations