https://aureatelabs.com/blog/easiest-way-to-load-your-custom-js-component-in-magento-2/
https://r-martins.github.io/m1docs/videos/fundamentals/add-a-javascript-module/index.html
https://github.com/nans/Magestudy/tree/master?tab=readme-ov-file
There are 3 ways to add JS
- Layout XML File
- Via data-mage-init and using RequireJS Configuration(Must add require-js.config file)
- Via <script type=â€text/x-magento-initâ€>
1) Via Adding Layout
You can add JavaScript files to specific pages or all pages using layout XML files.
Example:
Layout XML:
<?xml