byhemechi
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 ![]()
Trending in Proposals: Ideas
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
This might be a huge rabbit hole. Think of mount callbacks connecting to presence, pubsub or the likes triggering side effects beyond what you really intend on a prefetch. You might also need to be able to run two LV processes side by side unless you dig in real deep and remodel probably half of LV to add a new specialized prefetch rendering mode.
aloukissas
I would love to see this. It’s so common nowadays, it’s a miss on Phoenix not to have something like that OOTB.
Btw I kind of hackily did this (don’t run this in production, probably) like so:
harrisi
I would recommend using
fetchwithpriority: lowinstead of embedding an iframe to reduce memory, not modify the DOM, etc. I’d also recommend usingmouseoverandmouseout, and further would recommendpointeroverandpointeroutinstead to support more pointing devices. For both of those, obviously you want to make sure the changed behavior is acceptable/handled correctly. I also think the 100ms delay is kind of counterproductive for this use, but I get it. Usingfetchinstead also allows you to easilyabortthe request if desired.You also asked about this behavior in relation to Next on Slack, which does the hover logic when
prefetch=false. Forprefetch=true, which fetches the linked page when it’s in the viewport, this can be done pretty easily with the Intersection Observer API.As far as the interaction with liveview, I don’t have anything useful to add, unfortunately.
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.
harrisi
Yeah, I think it would only help when using
<.link href=foo>, which does an HTTP request, as far as I understand. For live navigation, I don’t know enough to say if the familiar “prefetch” tricks are useful, but I wouldn’t expect them to be.aloukissas
I think the approach that astro does is the cleanest and mostly leveraging browser standards:
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!
harrisi
Unfortunately the only option of the three that is actually available in >80% of user agents is
fetch. This may not matter for certain purposes (if you know or are able to require your users to use Chrome, mainly), but I’m personally not a fan of using Chrome-only features (rel=prefetchis not Chrome-only, for what it’s worth, just not as widely available asfetch).Anyway, still not sure how relevant any of this is to liveview
aloukissas
wdym? this works on chrome/chromium, safari, firefox? Plus most of the world is on Chrome. Would you really not ship an optimization for the majority of the world because it’s chrome-only? Sounds like a terrible trade-off!
rhcarvalho
I looked at some of the Astro docs to understand/remember what it is all about: Why Astro? | Docs
IIUC, Astro allows one to build server-rendered static pages. Navigation then means full/regular HTTPS requests.
External links are not prefetched, so prefetching focuses on optimizing internal page navigation.
LiveView’s focuses on a different set of goals. Whereas Astro contrasts itself with other JS frameworks primarily targeted at building web applications (with login, dashboards, User Interactions, etc), LiveView is a tool for building just that, albeit in a different way.
LiveView has a persistent WebSocket connection and internal navigation over the WebSocket bypasses most of what goes on in an HTTPS request. I think Astro doesn’t have that.
Typical LiveView applications have state, and that complicates the applicability of prefetching as others have mentioned.
At this point I don’t know what are we actually trying to improve in LiveView with prefetching, or is it just trying to copy a solution to a problem we don’t have
aloukissas
Cross-site navigation in phoenix projects (liveview or not) is just slower compared to astro, nextjs, remix etc. All of them to prefetch on hover (or when a link is in the view port). This means fetching images etc. So navigating to another page within the site is instant.
If you think Phoenix is ok staying behind as the “slow” solution (e.g. try using hexdocs sidenav- it is def not instant), then fine