I am currently working on a TypeScript file that captures DOM events and sends data streams to AWS Kinesis. In my HTML, I have the following script for testing purposes:
<script type="text/javascript" src="./tracker.ts?projectId=123&apiKey=trac3ab1e-50fa-50b5-dab5-acce55e5cafe"></script>
Using Parcel, I created a bundle so I'm not directly attaching the ts
file in the HTML.
After running npm run dev
, the <script>
tag changes to:
<script type="text/javascript" src="./tracker.568463.js?projectId=123&apiKey=trac3ab1e-50fa-50b5-dab5-acce55e5cafe"></script>
The tracker.ts
contains a class Tracker
which loads AWS SDK and sends data streams to Kinesis.
I now want to load this tracker.ts
from another script, but I have some questions:
- How can this be implemented?
- How feasible would it be?
- What impact will it have on performance?
When attempting implementation, I tried a couple of things:
Firstly, I changed the
type="application/javascript"
in the <script>
tag to type="module"
, based on this reference. However, this did not work as expected and some parts of the code were not properly read.
Secondly, I looked into importing the Tracker
class from tracker.ts
as a module, referring to this source. But I am unsure about how to implement it in my specific case, and I also received a warning stating that tracker.ts
is not recognized as a module.