Dynamically transpiling?
mercmobily opened this issue · 4 comments
Hi,
First of all, apologies if what I am about to write is completely bonkers.
Having said that...
My understanding is that prpl-server-node will serve different directories (each one containing a different build of the app) depending on the browser loading the app.
Now... would it ever be possible to do the transpiling on the fly? This means that there would be one source of the app, all written in ES6, and that code would be transpiled as needed by the server before sending it over. The server would obviously cache the transpiled files, so that it doesn't do it every time.
Is this approach actually sane? If so, could it mean that we would no longer worry about creating different builds, and in general what browser will hit the app, since the server will always deliver the right files for the client.
Am I dreaming?
Hi @mercmobily. What you describe is actually what https://github.com/Polymer/polyserve does, although it is very much intended to be used only as a development server.
This approach would be technically possible in production, but I'd say you're better off doing as much as you can pre-deployment. That way your live production server is smaller, has more predictable performance, is less error-prone, has a smaller footprint for security vulnerabilities, etc. IMO the convenience you get from moving the build step into the server is small (apart from during development), since you can pretty easily automate the "build && deploy" process.
I am not convinced 100000%. At the moment there is the semi-abandoned https://github.com/MailOnline/transpile-middleware and https://github.com/babel/babel-connect (which is not abandoned but it's being used by a specific company).
Thanks to caching, the performance hit would be less than negligible.
I don't know.. maybe it's just me, but the thought of being able to serve files "as is", and never having to worry about outdated browser, gives me a fussy feeling :D
It is an interesting idea, but for this project we'll stick with the pattern of doing the build upfront.