Best practice for code optimization

Hi community,
I’m coding a small game with Phaser 3 to test it out and learn as I’m fairly new with this framework.
My game is already 200 lines in a single file and I’d like to ask if you know or have any tips regarding optimizing the code. Do you create other files and import them into the main .js file by using import JS?
Are there any tutorials to read about this topic?


Yes, you can use JS modules if you want to. There are probably some tutorials on this but I don’t know any.

1 Like

Hi @rn3000

I’m also new to the framework but what I can suggest to clean up the code a bit is have at least 2 JS files, 1 file such as main.js or index.js that has your game config and imports your 2nd JS file, and for your second file to handle the scene and class logic. For each scene, you can create a new JS file and import this into the main.js file that your HTML file calls.

1 Like

Thanks for your replies @samme @josh-bristow_GGL

1 Like

Sounds good, thanks!