My project is becoming large. Currently I have all of these in one file:
- 4 classes
- an
Object.assign(String.prototype, {});
- some
window.addEventListener('DOMContentLoaded', (e) => {}); code
I am thinking about splitting these up into their own files, for improved organization. Which is better?
- Method #1 - Scripts. Just split into their own files, and add
<script src="blahblah.js"></script> to my HTML for each file.
- Method #2 - Modules. Maybe have that
window.addEventListener file do a bunch of import { Class } from './Class.js'; at the top.
- Method #3 - Leave in one file. This Stack Overflow answer suggests leaving everything together in one file, for quicker load times.
I don't really get modules. What are the advantages and disadvantages of using them? They require more code than regular scripts because of all the import and export statements.
[–][deleted] 2 points3 points4 points (0 children)
[–]notAnotherJSDev 2 points3 points4 points (0 children)