Yes, your code can definitely be in a separate .js file, but you should know there’s nothing you can do to prevent the user from seeing your code, no matter where you store it. Browsers all come with robust developer tools built-in, which allows anyone to read your scripts.
Anyway, to save your JS code in a separate file, you could do this:
- Create a file named
myProject.jswith all your code.
- Save it in the same folder as your
index.htmlinstead of writing inside the
<script>tags, you can just add the relative path to your
<!-- First you download the THREE.JS library --> <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/99/three.min.js"></script> <!-- Then you link to your own scripts --> <script src="./myProject.js"></script>
I’m sure they use three.js as well because I saw them in the three.js examples.
Not sure where you’re looking, but there are tons of scripts directly under the
No, it doesn’t happen automatically. You’d need to search for tools that do it for you.
If you don’t mind me asking, why are you so concerned with people being able to read your code?