For a lot of JavaScript projects, such as Bootstrap (well you may argue that it is just a CSS framework, anyway this is not the point), the installation section comes two ways.
The first way is usually like this:
npm install bootstrap
and the second way is the one I know:
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
My understanding is that npm is the right way to go if I am using node.js to do back-end development. Suppose I am using other backends (say, Python, Java) and JavaScript is run only on the client's browser, I should stick with the <script src=""></script> approach. Is this generally correct?
Another closely related question is about the use of import statement, such as import bootstrap from 'bootstrap'. My understanding is that this syntax only works for the node.js backend and I cannot use it on an HTML page without a lot of extra effort. Is this understanding correct?
<script src=""would be affected by the backend technology. That is just pure HTML feature to load a JavaScript file. If you don't use that, you don't have many other options. You'd probably have to dynamically generate the HTML source and have the JS pasted in it but I can't see why you'd want that.