Marvin
Marvin

Reputation: 243

How to properly link external JS resources into a JS file?

I am creating a dashboard that shows different graphs in my web application. I got this code snippets and edited as needed. I realized that my web application is getting bigger. Therefore, I'd decided to create a separate javascript files for each graphs. Initially, I had all my tag at the bottom of my html page which works just fine. I also have external resources such as;

<!-- External Resources -->          
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>

<!-- Functions -->
<script>
    // more codes here. But these codes will go to new .js file
</script>

Question, on my new .js file, how do I link all these external resources correctly?

Thanks in advance!

Upvotes: 0

Views: 2118

Answers (2)

TadLewis
TadLewis

Reputation: 151

As long as they are included at the beginning of your HTML as you have shown here, you should be fine.

Upvotes: 0

Tobiq
Tobiq

Reputation: 2657

Unless the "external resources" scope their code, so you can't access it in the global scope, you will be able to access everything in a JS file, just as you would within a script tag, in the document.

If your javascript code is working between <script> tags, it will also work when you move it into a file, and replace the <script> tags with something like this:

<script src="/code.js"></script>

Upvotes: 1

Related Questions