---
title: "Where to write JavaScript  code for better performance or better flexibility?"  
description: "Where to write JavaScript  code for better performance or better flexibility?"  
author: "Anonymous User"  
published: 2021-07-19  
updated: 2021-07-19  
canonical: https://www.mindstick.com/forum/156510/where-to-write-javascript-code-for-better-performance-or-better-flexibility  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Where to write JavaScript  code for better performance or better flexibility?

What will be best way to [put](https://answers.mindstick.com/qa/111890/can-you-explain-the-difference-between-put-and-post-http-methods) my [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) [Code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii)? May I put it on [external](https://www.mindstick.com/articles/12810/how-to-connect-tablet-to-external-monitor-or-flat-screen-tv-using-computer-adapters) [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) or in a same file?

## Replies

### Reply by 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.

\


---

Original Source: https://www.mindstick.com/forum/156510/where-to-write-javascript-code-for-better-performance-or-better-flexibility

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
