water

water

Phx.gen.html vs phx.gen.live

I’m reading, 1. Intro to Contexts — Phoenix v1.8.8, and it’s all about phx.gen.html. When would you use phx.gen.live instead?
I generated both and they look similar/identical in the browser.
They both use .heex files

mix phx.gen — Phoenix v1.8.8 says:
live has Liveview
html has Controller and View

I’m building my first application and I don’t know which to choose.

First Post! Switch mode

w0rd-driven

w0rd-driven

There are differences “under the hood” primarily. With gen.html you get a controller and take the traditional MVC approach with a single page call to your router. With LiveView there’s the addition of websockets where the GenServer takes the place of a traditional controller.

The primary difference is that web socket that requires a more persistent connection. LiveView is mostly both an Elixir backend as well as front end. Normal views (I’m not a fan of the term “dead views”) relies on JavaScript for more frontend behaviors. If you’re looking to integrate things like React, Vue, or Svelte you’ll have a slightly easier time if the backend is not a LiveView. It’s not that you can’t marry a heavy JS frontend with a LiveView backend, its just that fetching is handled a lot differently.

There is a lot more to each topic but if you’re making something that’s targeting crappy internet or things like phones, you may not want to choose LiveView. You can have great experiences and fortunately there is wide browser support for web sockets but particularly very old browsers don’t support them well or at all.

If this were me and I wasn’t aware of typical MVC architecture I would create 2 prototype projects generating both phx.gen.html and phx.gen.live. It’s a good way to get intimately familiar with both. I believe the majority of the Phoenix books do just that. They start you with normal views before moving to live.

— All posts loaded —

Where Next?

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement