Where to write JavaScript code for better performance or better flexibility?

What will be best way to put my JavaScript Code? May I put it on external file or in a same file?

Last updated:7/19/2021 5:18:03 AM

1 Answers

Ethan Karla
Ethan Karla

There is no best way to use a JavaScript file in your code, it may vary depending on the usage situation and project wise. But most of the time the JavaScript needs to be kept in a separate .js file.

That is why when the browser loads the web page, when it reads the external JS file it creates a cache and when the user opens it again it is stored on the browser for faster access to the website. . So, the best practice to use JavaScript is to keep it in separate file and link it with your code otherwise you can use it in the same file if your requirement is different for your project.


Answer