The compiler is about 730k compressed, not 10 MB. You can also lazy load it so that you show code before being able to run it.
Being in a worker only causes the synchronous fetches to not block the main thread. It's still terrible for performance as you lose all ability to load files in parallel.
It's really not that difficult to pre-traverse the import graph and fire off as many parallel fetches as the browser will allow.
Thanks, you're right, I was looking at the unminified version. Minified is 3.4 MB uncompressed, 730 KB compressed. That's still crazy considering that you could avoid it by compiling your code on the server (which can be extremely fast if you disable type-checking) rather than shoving that responsibility onto your user's browser. Might be reasonable for a big web application with megabytes of other scripts, but not for a normal website.
Oh, I wouldn't use something like this for the main code of a page. You should absolutely just compile and bundle the TS once, rather than on every page load.
But there are cases where you want to be able to run arbitrary TypeScript in the browser - in our case it was inline editable code samples - and for that running the TS compiler efficiently in a worker is great, and 730k isn't that bad. You probably also have 500kB - 1MB for a decent code editor too.
That's totally fair. The OP seems to be intended for your main page logic:
> TypeScript is still second-class citizen with regards to browser adoption, there is a proposal to fix that, but until then we have to use tooling, bundlers, build steps that are an impediment for when you want to quickly create a short demo or PoC.
(Of course, just for "a short demo or PoC," but will anyone be motivated to rip it out before that's no longer feasible?)
So I assumed you were talking about something similar. But using this approach to compile user code makes a lot of sense.
Being in a worker only causes the synchronous fetches to not block the main thread. It's still terrible for performance as you lose all ability to load files in parallel.
It's really not that difficult to pre-traverse the import graph and fire off as many parallel fetches as the browser will allow.