Why would LiveView send a static footer over the wire on every page load?


I have a layout in live.html.heex.. Last part of this is a <footer> that says “Copyright 2021 John Smith Industries.” This is sent on every page navigation over the wire, even though it is completely static content and never changes. What is causing this? I’m pulling my hair out trying to figure it out! Thanks.

Likely related but it appears EVERYTHING in live.html.heex is being sent on every page navigation. That seems peculiar to me, but this is the first time I’ve looked into minimizing data sent over the wire so perhaps this is actually the intended behavior?

Please clarify what do you mean by “page navigation” do you mean between different liveviews, a la live_redirect/2 or to the same liveview, a la live_patch/2?

In the second case I believe that whatever in the the layout will not be sent again. However in the first case, phoenix has no way to find out that the two different liveviews have the same layout and has to err on the safe side.

I am indeed talking about live_redirect/2. If this is the intended behavior, who am I to argue, but I’d hope there’s a better reason than not knowing they have the same layout…LIveView sure knows a lot of similar things; it seems like there would be a way to know it’s the same layout :slight_smile:

Ya, live_redirect/2 shuts down the current LiveView process and creates a new one, which is the point of it—It’s like you’re navigating to a whole new fresh page within the same session (here are the docs: Phoenix.LiveView.Helpers — Phoenix LiveView v0.17.5).

Are you using multiple LiveView views? If not, you can just use live_patch/2. Otherwise, if you really don’t want this behaviour, I recommend looking into using stateful components instead of creating separate LiveViews for each page. Otherwise, you’re still getting everything over websockets, so it’s still dang fast :slight_smile:

I am using multiple LiveViews. It’s certainly fast…I just am having trouble following why live.html.heex can’t be treated the same as root.html.heex as far as diffs. None of that content gets sent again, even though the LiveView process is shut down and a new one is started. I haven’t tried, but I suspect some dynamic content could be put in root.html.heex and it would be updated accordingly.

Maybe it’s more academic than practical, given how much faster it is than HTTP page loads, but I have a curious mind :joy:

Are you sure?

root.html.heex is not change-tracked. No changes → no updates.


I learn something everyday. Indeed, the root layout is not transmitted, so the caveat is that you should not put any dynamic content there, other than the special cased Phoenix.LiveView.Helpers.live_title_tag/2 Also you cannot put_root_layout in your liveview.