I am trying to use axios for data loading. As I am new, i got confused where should I install axios js.I tried to install on client side. Is that alright?
CodePudding user response:
Javascript files need to be hosted by a local (to the file invocation, not store) runtime engine. In a browser, for example, that might be the js v8 engine. Remotely, on a server, that server would have to have a local js runtime, presumably Node.js. The point is, if you want the js code to run in a browser, tag it in the html page, the browser will fetch the file from the web server, load it locally, and run the code. Otherwise, you an invoke it on the remote server, if the remote server has a runtime host such as Node, in the same way you invoke anything on a server; with a URI call (an example might theoretically be "https://......com/js-files/axios.js", and depending on if the server is configured to exec the resource, or fetch it, that's what it will do. Axios is isomorphic, so it can either run on the server in Node (if the server is correctly configured), or an HTML document can fetch it via a tag, and run the code locally, in the browser window/DOM. Is that clear?
CodePudding user response:
You can do either or both! They are separate runtimes/environments.
According to the docs, Axios is a Promise based HTTP client for the browser and node.js. So it really depends on where you want to initiate the request.
If you want to do it on the browser consider adding the package in the HTML either via a script tag or a bundled js file:
See installation steps: https://www.npmjs.com/package/axios#browser-support