JavaScript Errors

Nowadays almost every Joomla extension uses JavaScript to create a more responsive website for a better user experience. Mostly all JavaScripts rely on a JavaScript library like jQuery, Mootools or others. Using different scripts on a webpage can cause conflicts between them. This tutorial helps you to detect and resolve these script errors.


How to Detect Errors?

If your website does not work as you expect when you click something or if the animation stopped working, this could be the result of a JavaScript error. In case of an error, the script execution will be stopped by the browser. While some pages might still work, others don't. Not every script is being loaded on every single page of your website. A way to investigate these errors is to use the browser's debug console on the page where the error occurs. These developer tools will show you the script-errors including information about what went wrong, the file and line number, and the line of source code that caused the error.

Usually the errors are caused by a combination of multiple Joomla extensions. The browser's debug console will help you identify the scripts and their related files on your web server. Once you have identified the extension, you can try disabling it to make sure your page works without any errors again.


How to Resolve Errors?

If you've detected a JavaScript error on a page you need to find its origin. Usually the errors are caused by an extension or combination of multiple extensions. The browser's debug console will help you to identify the scripts and their related files on your webserver. Once you have identified the extension you can try disabling it to make sure your page works without any errors again. If the error is gone, you've found the extension causing the conflict. Now you can look for the extension's configuration option and see if it lets you enable/disable loading a JavaScript library like jQuery to resolve the errors.


How to Prevent Loading jQuery Multiple Times?

There is an ongoing discussion in the Joomla community on how to prevent loading jQuery multiple times across extensions. We have already taken steps and measures by implementing a widely accepted solution. We register through JApplication whether jQuery is loaded or not. In case a 3rd party extension loads the jQuery library you can use the following code snippet to prevent ZOO, Widgetkit or Warp theme from loading it twice:

// load jQuery, if not loaded before
if (!JFactory::getApplication()->get('jquery')) {
    JFactory::getApplication()->set('jquery', true);
    // add jQuery
    ...
}

You can also get in touch with the 3rd party extension developer and kindly ask them to implement this.

ZOO Documentation