Any way to upgrade jQuery version in Confluence?

Is there a way to upgrade the inbuilt-version of the jquery Library (v1.6.4) to a newer version? (e.g. 1.7.2)

I'd much rather have a single instance of jQuery present in my site, rather than having to fetch it twice and thus double download time/etc. Ideally Confluence 4.2 would have it by now (v1.7 was released in November last year), but I understand the "tested with" argument. But it would be nice to be able to, by choice, specify a newer version somewhere in a config file or the admin interface, etc. Can this be done?

---

If the answer is NO, then maybe someone can help me with a workaround:

I am trying to use a third-party javascript library that depends on 1.7. I have been trying to work out how to use jquery's .noConflict() but to no avail.

I'm using Confluence 4.2.5; with the Zen Foundation theme plugin (although I've tried switching back to Default Theme as well).

And I'm then trying to load in Twitter Bootstrap as a library.

I've tried the Zen approach; of loading in javascript files using the brand.properties file -- but have similar issues; and so for testing purposes I also tried using "Custom HTML" in the Admin interface -- and inserting the following there:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script>
   $.noConflict();
</script>

Doing this, and nothing else (e.g. not even getting to use the new jQuery) when running on Safari for Mac (and Chrome) results in the following error in the console:

RangeError: Maximum call stack size exceeded. jquery.js:6939

And the page takes a good 20 seconds to load before the error is displayed (eg. some form of infinite loop being hit).

Playing around with moving the noConflict() before the script src, adding the (true) parameter, etc doesn't seem to help.

Any ideas would be appreciated.

1 answer

1 accepted

1 vote
Accepted answer
Have you tried using the jquery user macro, which deals with potential clash issues that comes with referencing different jquery versions? It was written by a friend/colleague of mine, originally for Confluence 3.5. https://confluence.atlassian.com/display/DISC/jQuery+User+Macro

Thanks Charles - I had looked at that macro, but it didn't quite do what I was after (it deals with inline javascript, rather than included libraries). That said, testing the macro and seeing what it generated helped me understand a way to use .noconflict() with Confluence -- and I managed to get around the 'stack size' issue.

I ended up putting this into the Custom HTML admin setting:

<script>
	jQueryOriginal = (typeof jQuery == 'undefined') ? null : jQuery;
	if (typeof jQuery0 == 'undefined')
		document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"><\/script><script type="text/javascript">jQuery.noConflict();<\/script>');
        else 
		jQuery = jQuery0;
</script>
<script src="/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap.min.css" type="text/css">
<script>
        jQuery0 = jQuery;
        jQuery = jQueryOriginal;
</script>

And that seems to do the trick.

I swear i'd tried something very similar yesterday and was still getting that 'stack size' error, but go figure.

It's not the perfect solution though, as you end up with two versions of jquery loaded in the page.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 24, 2018 in Confluence

Atlassian Research opportunity with Confluence templates

Do you use templates with Confluence? Take part in a remote 1-hr workshop. You'll receive USD $100 for your time!   We're looking for people to participate in a   remote 1-hr workshop...

1,102 views 17 14
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you