4 ms·
Personally I want to move away from JavaScript and its ecosystem. There is https://hexdocs.pm/phoenix_live_view/js-interop.html https://hexdocs.pm/phoenix_live_
by johnisgood 4y ago
Personally I want to move away from JavaScript and its ecosystem. There is https://hexdocs.pm/phoenix_live_view/js-interop.html https://hexdocs.pm/phoenix_live_view/js-interop.html though. For the record, Phoenix does use JavaScript for its "LiveView"[1], but I think it is optional? At least I remember someone telling me this when I was complaining that generating a basic Phoenix project (using "mix") is too bloated due to JavaScript and such.
[1]
[...]
./deps/phoenix_live_view/assets/js/phoenix_live_view/view_hook.js
./deps/phoenix_live_reload/priv/static/phoenix_live_reload.js
./assets/package-lock.json
./assets/vendor/topbar.js
./assets/js
./assets/js/app.js
[...]
- elicksaur 4y agoIt uses websockets, which as I understand it, browsers only allow interfacing with them via JavaScript (at least easily). Is there a tech stack/protocol that gets comparable functionality to websockets but without using JavaScript?
- evadne 4y agoPhoenix LiveView uses JS because the core of the tech requires the server to compute diffs & the client to patch the DOM accordingly. This is why a JS package is needed alongside the other default package from Phoenix, which brings Phoenix Sockets & Channels capability (which builds on top of transports such as Websocket). Previously have seen: https://github.com/patrick-steele-idem/morphdom https://github.com/patrick-steele-idem/morphdom Can check: https://www.npmjs.com/package/phoenix_live_view https://www.npmjs.com/package/phoenix_live_view
- johnisgood 4y agoFor anyone wondering, this is where I complain about Phoenix being bloated[1], and others have informed me that "There’s no JavaScript unless you write it into the template.", and that I can reduce the bloat in this way: "You pass the `--no-assets` flag when using `mix phx.new`"[2] I do not know how true it is today. [1] https://news.ycombinator.com/item?id=31317545 https://news.ycombinator.com/item?id=31317545 [2] https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html
- di4na 4y agoIt depends what you do. If all you want is http requests and assets, no js needed. Being html or api. If you want to handle a websocket and have a 2 way bindings, then no way around it. But that is not phoenix fault. It is the reality of the browsers api. It is pretty minimal js though.
- ricketycricket 4y agoAs one of those others, I can confirm this is indeed still true as of Phoenix 1.7. `--no-assets` will not add any CSS or JS to the project other than empty `app.js` and `app.css` files in `/priv/static/assets` for you to fill in yourself if you want. You are completely on your own to implement an asset pipeline of your choosing. Of course, if you want LiveView you will have to bring some JS back in.