marciol

marciol

Phoenix LiveView vs SPA

Please, let me know if this kind of discussion already took place in another topic
.
Hi all, how do you consider if is better to build an app around SPA paradigm instead of use Server Side Rendering technologies.

I was thinking much about it and my first impressions is that familiarity with the stack has more weight than some objective criteria, given that a lot of apps can be developed with one or other approach, as we see with several apps in the wild.

Take for instance an app that I use everyday, Kanbanize. It is built around some server side rendering tech and it is awesome, but I know that some will tell that the UX is subpar, the same can be applied to Basecamp and Hey.

It’s get worse when you read the Twitter message from Chris, when they show that LiveView can exchange messages between frontend and backend more efficiently than a hand made SPA:

https://twitter.com/chris_mccord/status/1252997316103081984?s=20

So what do you think about it, how do you decide when thinking about start a new project with limited resources, as a indie hacker’s project for instance.

Most Liked

bjunc

bjunc

I think this topic really could be broken out into a dozen smaller pros/cons comparisons. It would be beneficial for the community, as the topic of full-stack Elixir comes up quite often. To really answer your question, it’d be worthy of a detailed blog post (I might be volunteering myself in writing this). However, if you have a specific question / sub-topic, I’d be happy to answer it here.

That said, here are 6 reasons that come to mind to continue reaching for JS in the UI:

  1. JS devs tend to also be HTML/CSS devs with more UI experience than Elixir devs. It’s not just a language preference, it’s also domain experience. Do you know when to reach for flex-box vs grid? JS devs are more likely to have a better understanding of UX, experience in the many browser quirks, and an “eye” for UI. Also, UI devs tend to be cheaper than Elixir devs. The economics of specialization and comparative advantage are at play.

  2. Plenty of turn-key UI libraries. For instance, Material components exist for Vue, React, etc.. I keep seeing these really primitive LiveView UIs with basic CSS. That’s just not what a modern app looks like. Are we going to build a multi-select, token dropdown menu that support slots, is accessible, and mobile friendly in LiveView? Yes? How about the other 20+ common Material UI components? What about charts? Are we going to build a LiveView library with parity to D3.js? What about animation libraries like GreenSock? Are we going to “stream” position updates, or have lightweight UI libs that handle transitions based on configs sent from LiveView? Is that even worth it?

  3. UI components. For instance, Vue single-file-components (SFC) are a HUGE benefit in my experience. Keeping your script, CSS, and HTML together in the same file makes maintenance really useful. Vue will automatically scope your CSS to prevent accidental specificity conflicts. Transpilers like SCSS are easy as well. The modules will live update in the UI on a per-module basis. Meaning, without a full page refresh you get just the module that swaps out. Super useful on big apps that have long compile times.

  4. Repurpose the UI for mobile. Many apps are built in React Native (or similar); often built by the same team that is building the web UI. Elixir doesn’t have an option for that.

  5. Offline support / service workers.

  6. Centralization / decentralization. By offloading rendering work to the browser, we decentralize computation resources. With LiveView, you’re now concentrating all that work on the servers. Servers are pretty cheap, but the client’s browser is free.

Hope that helps. I am very optimistic that JS is being attacked from multiple angles (LiveView, WebAssembly, etc.). However, we’re not doing ourselves any favors by comparing LiveView to narrow JS use-cases and ignoring the many aspects of modern JS. Like I said, for smaller / marketing projects, blogs, etc., LiveView could definitely work. For larger projects (or ones that could grow into larger projects), I don’t yet see LiveView as a viable replacement.

crusso

crusso

Early stage barriers to success on the web are typically time-based. You need to rapidly find the right solution that will draw customers/eyeballs. You need to be able to put features up quickly and iterate as rapidly as possible to find what will draw people in to your web application. You don’t want to spend inordinate time creating experiments that might fail while exploring your options.

To that end, LiveView will get you up and running as quickly as possible while allowing you to experiment to find what works for your business model.

Later, if you have a successful site that needs to scale, you might consider migrating to an SPA. But to give your ideas the best chance they have of finding footing in a marketplace, I don’t see how you could do better than to start with LiveView.

gfviegas

gfviegas

For me personally, I almost exclusively use Phoenix for APIs only. When I need this realtime updates stuff, I use GraphQL subscriptions.

As a fullstack developer that sometimes hire some frontenders to help building interfaces, it’s way more organized and flexible. With an API built, you dont need to share your business-backend code with frontend code directly. It also gives you a quick way of building mobile apps, external integrations, or even a complete rework of your web interface easily.

Of course one of this frontends can be a phoenix app, integrating with a backend app which is also an API, but I see little value there. At least not without using a JS framework anyway. You can SSR in phoenix with react, for example. But I’d still split the codebase in many scenarios.

Where Next?

Popular in Discussions Top

andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
Donovan
Hello everyone, I’m so glad to have discovered this awesome community. Thanks for creating it! This is my second post, and apologies for...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
joeerl
I’m playing with Elixir - It’s fun. I think @rvirding does give Elixir courses these days. Re: files and database - when I given Erlang ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New

Other popular topics Top

TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42158 114
New
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39523 209
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52774 488
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement