Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to reference/load .js files from Confluence server

Dustin Harrah May 24, 2015

I have a .js file that I need to reference for some code I am writing. I am currently testing on a page with the HTML Macro. I have uploaded my js file to my server in the following location:

/opt/atlassian/confluence/confluence/includes/js

In my HTML Macro, I type the following:

<script type="text/javascript" src="/confluence/includes/js/test.js"></script>

When I load my page, I see error 404 regarding my js file. It seems to be prepending "https://<confluence domain>.com/confluence/includes/js" (which I'm wondering if that's part of the problem somehow). I was able to find a CDN that hosted this particular .js file I am trying to use and when I point my HTML Macro there, everything in my code works as expected. So, the only problem I have now is the reference to my local file on the server. It really shouldn't be this difficult to work with a CMS smile.

I was referred here by Confluence Support since this is out of scope for their Support. They claim it "works" for them just fine but I continue to have problems on my own instance of Confluence using the exact same code that "works" for them. Hopefully someone here has seen this same issue and can direct me to a solution.

 

Thanks in advance!

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Dustin Harrah May 25, 2015

After reviewing all the paths I have tried, I realized I failed to add the ' / ' character before 'includes'. That is now working.

0 votes
Davin Studer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 26, 2015

FYI, if you upgrade confluence you will have to copy that .js file back to the includes directory as the upgrade will remove it.

0 votes
Dustin Harrah May 24, 2015

I'm not really developing a plugin, though. According to this Confluence article, I should be able to call any js file on my Confluence server (both in Custom HTML and the HTML Macro). That is not working. If I'm understanding your answer correctly, you are indicating that I need to create a plugin before I can reference the above article - is that correct? If so, the article does not specify this at all as being a prerequisite.

Nelson Carranza
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 24, 2015

Ok I see. I would try to remove confluence from the path; It worked for me in some other cases. I think I is related to finding the correct base url or contextpath https://developer.atlassian.com/confdev/development-resources/confluence-developer-faq/how-do-i-get-the-base-url-and-contextpath-of-a-confluence-installation Hope It helps, Nelson

Dustin Harrah May 24, 2015

I will try that. I did already try omitting 'confluence' and just start with 'includes' but that didn't work. Maybe I need to go the other direction. I will keep at it! Thanks for your input so far!

0 votes
Nelson Carranza
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 24, 2015

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events