Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.


DotNetNuke and jQuery: An Overview

Recently I received an email from someone who had attended one of my DNN training sessions asking to clarify some questions about jQuery usage. This person was just getting started with jQuery in DNN, and had inherited a skin that loaded jQuery itself, but they also realized that DNN was loading jQuery as well. They noted that everything seemed to be working fine, but were a little apprehensive that one day things may grind to a halt.

Instead of just replying to the email, I’m going to answer these questions publicly in hopes that it benefits others.

How does DNN load jQuery?


Years ago (late 2008, I think), DNN 5.0 added direct support for loading jQuery. Since then, the right way to load jQuery from a skin or a module, is to ask DNN to register it for you. So think of it like this – every time DNN loads a page, it’s waiting for someone to say “I want jQuery!”. If nobody says that – it won’t be loaded. If one module or skin says that – it will be loaded once. If 20 modules ask for jQuery, it will still only be loaded once. Same goes for jQuery UI, which was introduced in DNN 6.

When jQuery or jQuery UI is loaded by DNN, the DNN options set in the Host settings are used:

image

So if DNN loads jQuery, and the skin/module loads jQuery, which is actually being used?

The answer to this one is quite simple. The last one to load will win. This is because both of the scripts will be defining the global jQuery object. So the second one will literally overwrite the first one.

Any potential issues upgrading DNN, or using DNN modules?

Sure! You could experience a wide variety of issues if jQuery is being loaded more than once. It is really quite unpredictable given the variety of ways people can organize/load JavaScript on a page in DNN, and the extent to which they do (jQuery is really common).

If you are loading two different versions of jQuery, you may have functionality that depends on a particular version. If for some reason that version is being loaded first and getting overwritten by another (presumably older) version, your functionality would likely just stop working.

Additionally, there are some interesting repercussions for plugins when jQuery is loaded more than once, as plugins just extend the jQuery object. For example:

  1. jQuery is loaded by DNN. The jQuery object is defined.
  2. A jQuery plugin extends the jQuery object with its functionality.
  3. A skin or module loads jQuery. The jQuery object is redefined, and its like the plugin never got loaded.

Why do some modules have settings for loading jQuery?

In an effort to support multiple versions of DNN, module developers that create modules which depend on jQuery will often give the administrator an option to opt out of loading jQuery. If you’re opting out, the module developer assumes that you’re loading it via some other mechanism, presumably through the core functionality in DNN.

What to do?

Try to only load jQuery once. This means using the API to register jQuery if you are developing a module or skin. It also means telling any module that has the option to *not* load jQuery itself, but to use DNN.

Resources

Want to register jQuery the right way? Check out these community resources:

If you have any questions or any more techniques/resources please post them in the comments.

Comments

Timo Breumelhof
There's the jquery skin object now...
<%@ Register TagPrefix="dnn" TagName="jQuery" src="~/Admin/Skins/jQuery.ascx" %>
Timo Breumelhof Friday, November 15, 2013 1:46 PM (link)
Timo Breumelhof
Don't forget to add this too :-)
Timo Breumelhof Friday, June 20, 2014 4:01 PM (link)
Timo Breumelhof
Sorry...
Timo Breumelhof Friday, June 20, 2014 4:01 PM (link)
Timo Breumelhof
<dnn:jQuery runat="server" />
Timo Breumelhof Friday, June 20, 2014 4:02 PM (link)

Comment Form

Only registered users may post comments.

NewsArchives


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out