I have read a number of ways to add JS files to a Magento 2 project, but I haven't seen anywhere where the benefits / best use-cases for each are explained.
The use-cases that are most relevant to my projects are:
- Adding a JS library (eg. Owl Carousel)
- '' my own JS file with some basic click events and references to the above library.
And the init methods available (to my knowledge) are:
- Adding a file through requirejs-config.js and referencing it in a template file where needed.
- '' in an xml file within tags.
- '' via the Magento x-init method.
I assume that each method has a best use case due to the fact that there seem to be a few options.
Could anyone give a brief explanation or a link where the benefits/ use-cases are broken down?