Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use CDN in local javascript file

Tags:

I am trying to use Tone.js to make music with javascript. I get the error message "tonetutorial.html:26 Uncaught TypeError: Tone.Player is not a constructor" whenever I try to make it work.

I have at the top of my HTML file. I am currently using Brackets to write and preview my code.

This is my javascript function

function sequencer() {
const kick= new Tone.Player("Cartoon_Boing.mp3").toMaster();

const kickInputs = document.querySelectorAll(".kick");
}
sequencer();

this is the HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.0.2/Tone.min.js"></script>
<script src=tonetutorial.js></script>
<body>
    <h1>Music Maker</h1>
    <div class="drums">
        <div class="kick">
            <input type="Checkbox">
        </div>
    </div>
</body>

When I try to run this, I am being told that "Tone.Player" is not a constructor. can I not use the web cdn in this case? do I have to download the .min to my desktop?

like image 654
CharlieBakes Avatar asked Jul 15 '19 20:07

CharlieBakes


People also ask

Should I use CDN or local?

CDNs are best suited for today's modern websites which involve different types of media files and a combination of static and dynamic content. With a local server hosting your website, the scope is also quite narrow and focused, and you don't have to worry about the nature and configuration of a network of servers.

What is a JavaScript CDN?

A CDN (Content Delivery Network) is a group of servers spread out over many locations. These servers store duplicate copies of data so that servers can fulfill data requests based on which servers are closest to the respective end-users. CDNs make for fast service less affected by high traffic.


1 Answers

https://cdnjs.cloudflare.com/ajax/libs/tone/14.0.2/Tone.min.js does not include Player.

The releases page for the library shows that the latest released version is 13.4.9.

Possibly, 14.0.2 is buggy.

Using <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/13.4.9/Tone.min.js"></script> resolves the issue.

like image 73
Quentin Avatar answered Sep 29 '22 09:09

Quentin