byhemechi

byhemechi

Add an option to prefetch .link navigation

Many web frameworks (e.g. Remix, Gatsby) have an option for their link components that begins the navigation request on hover so that when the link is actually clicked ~300ms later the page is cached and ready to be swapped over. This compensates for network latency very effectively, my ping from Sydney to Frankfurt is about 280ms.

This would be an enourmous improvement in UX for people not geographically close to servers, and as nice as it would be to put everything on fly.io or some other edge equivalent it’s not an option for many people

My understanding of the challenges involved is that the biggest issue would be desync between what the server thinks the DOM looks like vs what is actually there if the link is hovered over but not actually clicked.

I would work on this myself but i don’t feel like my knowledge of liveview is adequate to implement this without creating a huge mess :slight_smile:

Most Liked

byhemechi

byhemechi

For writes you’re absolutely right, the best you can do is optimistic UI and spinners, but for reads you can get almost the same thing with an SPA by prefetching data. Usually, it takes one entire client.prefetchQuery inside a requestIdleCallback.

I am fully aware of the time cost of maintaining an SPA. I’ve been writing JS since we called interactive UI made without using flash or java “DHTML”, the number one way of fetching data on the client was jsonp and there was this exciting new function on the horizon called document.querySelector. If all you know is backend programming then yes it looks very scary but if you’re familiar with the environment and pin your dependencies frontend code is just as simple to maintain as backend code.

There is absolutely extra cost in developing the app, but there is also cost from lost productivity waiting for a loading spinner. There is a reason things like GraphQL/Relay exist and it is not for developer velocity. It is very easy to take loading times for granted if you live in the US or Europe where the servers are close.

If you watch this video of me using livebeats, every one of these page transitions would benefit from prefetching page contents. This is pretty much the best case scenario for an Australian connection with gigabit fibre with good peering. Compare this to this recording of me using Tidal, an SPA and you can see the transitions are almost instant, despite the server also having ~300ms of latency, as demostrated by when I open a playlist that is yet to be cached.

Somewhat ironically, the same sort of speed can be achieved with phoenix, but only if you use “dead” views, because link rel="prefetch" works just fine for full page transitions

rhcarvalho

rhcarvalho

Been looking at this thread and thinking…

I think the problem with fetch (and the iframe) in the case of LiveView is that it probably doesn’t help make the live navigation (over the persistent WebSocket connection) any faster, and brings questions about behavior.

JS fetch would probably cause only a “disconnected mount” of the prefetched page/LiveView, while the iframe would trigger both disconnected and connected mounts with a full LiveView process on the server which can’t really be reused when the actual navigation happens.

aloukissas

aloukissas

I think the approach that astro does is the cleanest and mostly leveraging browser standards:

  1. It prefers using speculation rules, if available
  2. It falls back to rel=prefetch, if available
  3. finally, resorts to using fetch()

They also keep track of already prefetched URLs in a set and bail early.

Prefetching can be configured to be global on the project, opt-in/out per link, etc. Very good ergonomics!

Where Next?

Popular in Proposals: Ideas Top

sbennett33
When building a component library, it is often useful to give users the ability to customize the underlying element or component to use. ...
New
woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New
azyzz228
The slow network is known to be an Achilles heel of LiveView’s architecture. Recently, I was working on creating a fast rendering map wi...
New
andreamancuso
Hey folks, This might sound niche, but I think it’s worth bringing up - especially given Phoenix’s reputation for being lightweight, por...
New
marcandre
I notice that most events have bindings (e.g. phx-keyup) but not the input event. The input event is the preferred way to interact with ...
New
engineeringdept
In 2026 double submit/session tokens are no longer necessary to prevent against CSRF attacks. Instead, we can use the Sec-Fetch-Site head...
New
sevensidedmarble
Hello all, Apologies if this has been proposed before I guess, but I have a very simple one: With the increasing importance of LV, I th...
New
BartOtten
I’d like to propose that we refrain from using the term "DeadView" as the opposite of “LiveView” and instead choose an alternative. A new...
New
spicychickensauce
I’ve previously explored what is possible today with hacks to implement view transitions in our apps: I have since created a fork to im...
New
Flo0807
Hello everyone! Phoenix LiveView v0.18 introduced the special attributes :let, :for and :if. In addition to the :if special attribute, I...
New

Other popular topics Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
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
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement