Page MenuHomePhabricator

Investigate mousedown/click relationship on links, for prerender purposes
Closed, DeclinedPublic

Description

The author of this JS library: https://instant.page/ Alexandre Dieulot, reached out to me stating that we should consider using it. Last time we considered doing any kind of proximity/hover-based prefetching, I believe we decided not to because our pages are riddled with links and some people point where they read. Which for someone with a metered connection, could turn out to be very expensive. The Save-Data exists, but it's unclear to us if users who would benefit from it know how to turn it on in their user agent. We don't want someone in a developing country to learn about it because they ended up having a huge internet access bill due to browsing Wikipedia articles using browser defaults.

We could consider, however, implementing the most conservative mode of that library, which is prefetching/prerendering on link mousedown. Before we get into that, though, I think we should measure the rate of abandonment (mousedown but cursor moved out before it turns into a click), as well as the typical delay between mousedown and click. Adding a prefetch link to the DOM and the user agent acting on it aren't instantaneous things (the browser is only supposed to do it when completely idle, including other tabs), so there's a possibility that the preloading attempt wouldn't be worthwhile in a lot of the cases because the delay between mousedown and click would be too short.

Event Timeline

Gilles triaged this task as Medium priority.Aug 26 2019, 8:41 AM

Before setting up a real world study, I've decided to implement the feature locally to check that it would do what it's supposed to, if the likelihood of click after mousedown is indeed high.

Testing out this idea of prefetch on mousedown using a browser-level user script, I see that it shouldn't be applied to logged-in users (would result in double fetching the page). For logged-out users, it results in a 304 on the click's request. Which means that there's still a server round-trip to do, even if the target page is fully cached. On my 18Mbps internet connection, the prefetch request took 57ms and the 304 took 46ms.

Now, that was using prefetch, which only cares about the main document. In this case, with a very high likelihood of clicking on the link, the more aggressive prerender might be worthwhile. Oddly, when requesting that the browser prerenders the link, it does so silently. But it's clear that having all the subresources prefetched makes a HUGE difference when everything has had time to prerender, with almost everything (the main document's 304 being a notable exception) coming from the prefetch cache.

The 304 is probably a byproduct of our caching headers for article content. I imagine it's set up that way for articles that get updated frequently (news, etc.). I wonder if we couldn't somehow tweak our article caching headers so that they would come from the browser's cache for a few seconds. Something like max-age=5 might do, and make prerender on mousedown even more effective. I verified that on Vagrant and it indeed makes the loading of a prerendered link instantaneous. The duration in seconds to cache something for can be tweaked based on the real-world measurements of deltas we see between mousedown and click on links.

Gilles renamed this task from Investigate mousedown/click relationship on links, for prefetching purposes to Investigate mousedown/click relationship on links, for prerender purposes.Aug 26 2019, 9:36 AM
Gilles updated the task description. (Show Details)

Change 532347 had a related patch set uploaded (by Gilles; owner: Gilles):
[mediawiki/extensions/NavigationTiming@master] Collect timing data about link interactions on the page

https://gerrit.wikimedia.org/r/532347

Change 532378 had a related patch set uploaded (by Gilles; owner: Gilles):
[mediawiki/core@master] Make max-age configurable for logged-out users

https://gerrit.wikimedia.org/r/532378

Change 532378 merged by jenkins-bot:
[mediawiki/core@master] Make max-age configurable for logged-out users

https://gerrit.wikimedia.org/r/532378

Change 532347 abandoned by Gilles:

[mediawiki/extensions/NavigationTiming@master] Collect timing data about link interactions on the page

Reason:

https://gerrit.wikimedia.org/r/532347

Krinkle claimed this task.
Krinkle subscribed.

Re-opening to remove experiment code from code to reduce complication.