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

How do I use a .js attachment on a page?

Jason Monsorno
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.
August 14, 2014

I've been writing custom javascript code in {html}<script></script>{html} tags on the page or another and including it, I've made User Macros and all that has worked fine but I don't want to continue that route. Instead I want to upload my .js files as attachments and include them, the best way I see is

{html}&lt;script src="/download/attachments/123/file.js" type="text/javascript"&gt;&lt;/script&gt;{html}

That seemed too easy and apparently was, Chrome is throwing an error when trying to load it:

Refused to execute script from 'http://confluence/download/attachments/4426187/HotFixCreation.js' because its MIME type ('application/x-upload-data') is not executable, and strict MIME type checking is enabled.

Any ideas how I can use my .js attachments?

3 answers

1 accepted

1 vote
Answer accepted
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.
August 15, 2014

Have you tried editing the mime type in the attachment properties?

Jason Monsorno
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.
August 17, 2014

I never clicked on properties before, it worked like a charm.

Jason Monsorno August 17, 2014

I never clicked on the properties before, worked like a charm.

0 votes
Olivier Carbone November 9, 2015

$.getScript is to include the file content in the body of the page. It's to work around the cache... it solve the shituation, but it's not a best practice.

Yes, Davin,  edit the content type of the js file to "application/javascript" is a best solution!

To change the content type of an attachment, please visit the view page attachment (viewpageattachments.action) and click in Properties of the js file.

0 votes
Jason Monsorno
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.
August 14, 2014

Not sure why it's not blocked but I can load it from JavaScript:

{html} &lt;script type="text/javascript"&gt; $.getScript('/download/attachments/123/file.js'); &lt;/script&gt; {html}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events