LiveView calls mount two times

Is it possible to have a fully static file to bootstrap the liveview? Assume I don’t care anything about SEO. Then mount() will only be called once.

Folks, you are over thinking this :slight_smile:

You have the option to defer loading until connected, cache, etc for expensive operations, which you’ll need to be carefully considering even if you weren’t using LiveView if you have such expensive ops. As with regular HTTP requests, make it work, then make it fast(er) as necessary. The disconnected + connected mount is also nuanced workload wise because while it may dup work on mount, it saves you from doing work on every other “request” as the user interacts with the application. You aren’t fetching current user, parsing and authenticating via HTTP headers, fetching permissions, etc just to begin processing an event.

5 Likes

Yes, this ^. Also, if you use live_redirect between pages, the double mount only happens once when the user hits the site, and then not on any other pages.

mount/3 is only as expensive as you make it.

5 Likes

But it is theoretically possible, right? If I want to make an analogy to JAMStack techs like Next.js, they can do pre-rendering and server-side rendering, however Phoenix right now can only do server-side rendering. Imagine if we can use Phoenix as a static site generator, with pages that can be further hydrated into live view? There must be some real world applications that can benefit from it.

If I want a static site generator, I’ll use a static site generator :slight_smile:

The current functionality works splendidly and is still a huge saver compared to for example hydrating auth on every single request on a page like you would do with GQL, web1.0 or SPA based flows.

That’s a whole different can of worms right there. Not only do you not want to do db queries for the static render, you don’t even want to need phoenix for it.

I am. However:

  • The various javascript based generators are very complex, slow, and if I break something it is very hard to debug (at least for me)
  • Hugo is fast. However its templates only offer limited functionality. If I want to do serious work to interact with a server side (Phoenix), I would need to write some Javascript, Go and Elixir at the same time?