user1159265
user1159265

Reputation: 27

jQuery loading twice

I am creating joomla templates and want to add a simple jquery script. The problem is that there are other joomla extensions like GCalendar which load their own jquery.

This means:

  1. If I add <script src="http://code.jquery.co.... it will conflict with the jquery of other extensions
  2. If I don't add that code, the new script will not work if other jquery loading extensions are not installed.

Any ideas?

Upvotes: 0

Views: 889

Answers (2)

hunter
hunter

Reputation: 63522

You can check if jQuery is defined in script and load it if it has not been loaded prior.

You may run into functionaliy issues if the previously loaded version of jQuery is not a version you are supporting


<script>window.jQuery || document.write(
        '<script src="/scripts/jquery-1.6.2.min.js"><\/script>')
</script>

Upvotes: 1

Seth
Seth

Reputation: 6260

If you are hosting the library yourself you could wrap the entire library with an

if ( !jQuery ) {
    // jQuery Library
}

Or you could look into a library like RequireJS to handle your dependencies.

Upvotes: 1

Related Questions