If you are writing a module for DotNetNuke that depends on jQuery, you must find a reliable way to make sure jQuery is loaded. Furthermore, you must make sure the right version of jQuery is loaded and must also ensure the rest of the DNN installation is not affected. Here is how you can do that.
Goals:
1. Detect whether jQuery is installed
2. Determine whether the right version of jQuery is installed. I will use 1.4.2 as my base.
3. Make sure to not cause conflict with other libraries that might be using the $ variable
Code:
<script type=”text/javascript”>
// Check whether jquery 1.4.2 or greater is loaded
var loadJQuery = (typeof (jQuery) == 'undefined' ||
jQuery().jquery < "1.4.2");
// Add a marker to invoke no conflict when the $
// is mapped to a library other than jQuery
var callNoConflict = (typeof ($) != 'undefined'
&& typeof (jQuery) == 'undefined')
if (loadJQuery) {
var filename= ‘your path to the jquery file’;
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", filename);
document.getElementsByTagName("head")[0].appendChild(fileref);
}
if (callNoConflict) {
jQuery(function(){
jQuery.noConflict();
});
}
</script>
Will Strohl has put together a great article on the best practices for using jQuery within DNN




Posted by Will Strohl on November 14, 2010 at 3:06 pm
Have you found any code or UI latencies, using this method?
Posted by Mitch Labrador on November 14, 2010 at 5:50 pm
Hi Will
I can see how this might have a tiny perf hit compared to just including the ref directly in the head element. However there is no other reliable way to load it when dealing with dnn4.x. DNN 5 and above this is not as much of a problem as you can pretty much rely on the framework.
Mitch
Posted by Eric on November 22, 2010 at 3:05 pm
This is a nice script! We have run into this issue a number of times.