JavaScript Modules take over the world!
As I was working on my AssemblyScript port I also rewrote my login page to utilize JavaScript modules rather than just regular old files.
Just cool
The modules are just cool. They isolate your code quite nicely inherently because of their own nature. You load the code as a module and it will execute the JavaScript therein but you have to explicitly put your code on the window
if you want to expose it to the site/application itself. This allows for some very handy code organisation and just makes everything clearer.
Why not more
Why are not more people using this way to deploy/run their SPA's I have no idea. I think it is great and it is super easy to integrate. For example there exists this micro-frontend mindset these days, for which this is a great implementation candidate.
You can just load a full URL right out of the code, just like Deno can do, all because of their shared import statement. The module name can be a relative or absolute url.
I used this to load in the loader
from AssemblyScript to make WASM interaction much easier.
Structure
The sense I am getting these days is in the olden days everything happened in the backend only, then we slowly moved over to backend generally only did data and the frontend did the UI/UX and so there was this big seperation, to now where we want to have everything in the frontend (aka the browser) like the backends of yore used to do.
I do not think this will be very successful in the long run because there is just so much that a server is better qualified for doing than the browser it seems like a bad idea.
Barring all that it must be said with JavaScript modules you can organize and layout your code structure more like a backend than a frontend. I quite liked that aspect. I could make some classes and services even that did something that would only be exposing an API for internal use and also keep some things internal that made it clear what you should be able to use and what not.
It is my favourite way to code in the JavaScript now in the frontend and I just ported/rewrote all the loose code I had into this nicely integrated and organised usage of JavaScript modules.