Dev.to WebDev πŸ›  Dev πŸ‘ 0 πŸ“– 7 min read

We tested View Transitions and Speculation Rules. Here's why we rolled them back

At Subito, Italy's leading classifieds platform, one of the most frequent user journeys is going from a listing page to an ad detail page, what we call the "AdView." It's the moment where browsing turns into intent: a us

We tested View Transitions and Speculation Rules. Here's why we rolled them back

At Subito, Italy's leading classifieds platform, one of the most frequent user journeys is going from a listing page to an ad detail page, what we call the "AdView." It's the moment where browsing turns into intent: a user has spotted something interesting and wants to see more. We wanted that moment to feel instant, and we wanted it to feel good.

Two web platform features looked like an obvious fit:

Both are exactly the kind of thing you reach for when you want faster, smoother navigation. In practice, our AdView page was already rendering in well under 80ms server-side. That left very little room for Speculation Rules to shave off, and it forced us to be honest about whether the transition animation was pulling its weight on its own. So we ran an A/B/C/D test to find out, and the result surprised us.

The setup: four variants, one experiment

We split traffic four ways:

  • A, control: the current experience, no changes.
  • B, Speculation Rules only: prefetch the AdView HTML when a user hovers over or touches an ad card in the listing.
  • C, View Transition only: animate the switch from Listing to AdView on click or tap.
  • D, both combined: prefetch and animate, aiming for a near-instant, smooth handoff.

The hypothesis was simple: if navigation feels faster, smoother, and more seamless, we should expect users to stay more engaged and therefore make more AdViews (views of a listed item's detail page).

We tracked AdViews as the primary metric, LCP (p50/p90) to quantify the impact on rendering speed, and a custom "prefetch calls per user" metric as a proxy for the extra infrastructure cost B and D would introduce: the more calls, the higher the cost.

Speculation Rules and View Transitions were wired independently, so Variant B or D turned Speculation Rules on, and C or D turned the transition on. That separation mattered once we got to the results, because it let us tell the two features apart.

To measure the impact on LCP quantiles, we used a technique proposed in this Spotify Engineering article, which allowed us to calculate bootstrap confidence intervals at scale, across millions of observations.

How Speculation Rules actually worked

The implementation injects a <script type="speculationrules"> block at runtime, scoped to ad links in the listing:

{
  prefetch: [{
    where: { selector_matches: '.spec-rules-moderate a' },
    eagerness: 'moderate'
  }]
}

We started with prerender instead of prefetch. Prerender is the more aggressive option: the browser actually renders the target page speculatively, executing its JS, which is great for perceived speed but expensive for us to serve at scale.
We switched to prefetch, which only fetches the document bytes ahead of time without executing anything, once it became clear it gave us most of the speed win at a fraction of the server cost.

To confirm a page was actually served via a speculative prefetch, rather than a normal navigation, we read the standard Navigation Timing signal:

performance.getEntriesByType('navigation')[0].deliveryType === 'navigational-prefetch'

That single boolean check fed our "prefetch calls per eligible user" cost proxy, a way of putting a number on infrastructure cost before deciding whether to ship anything permanently.

How the View Transition actually worked

This part took more care than we expected, mostly because of a timing gap between the browser and React.

Cross-document view transitions (the kind that animate between two full page navigations, as opposed to a same-page DOM swap) are opted into declaratively via a CSS at-rule:

@view-transition {
  navigation: auto;
}

and controlled through two navigation lifecycle events, pageswap (fires on the page you're leaving) and pagereveal (fires on the page you're arriving at).
Both events can fire before React hydrates: a listener registered inside a useEffect will reliably miss the first paint, because by the time React has mounted, the transition has already started; so the logic that decides how to animate, forward vs backward, based on event.activation.navigationType and comparing history indices, had to live in a plain inline <script> tag in <head>, executed synchronously as the HTML parses, not in a React component.

We split this into two pieces:

  • a tiny inline script for the timing-critical part
  • a regular client component that just sets or clears a view-transition cookie depending on the experiment variant. If the cookie isn't set, the inline script is a complete no-op, so users outside the treatment groups pay nothing for it.

The client component only toggles the cookie based on the experiment variant:

export function ViewTransition() {
  const enabled = true or false, based on experiment variant

  useEffect(() => {
    if (enabled) {
      document.cookie = 'view-transition=1; path=/';
    } else {
      document.cookie = 'view-transition=; path=/; max-age=0';
    }
  }, [enabled]);

  return null;
}

The inline script is the part that actually has to run before hydration. It checks the cookie, opts the document into @view-transition, and figures out the direction from the navigation events:

(function() {
  var hasCookie = document.cookie.split(';').some(function(c) {
    return c.trim() === 'view-transition=1';
  });
  if (!hasCookie) return;

  var style = document.createElement('style');
  style.textContent = '@view-transition { navigation: auto; }';
  document.head.appendChild(style);

  window.addEventListener('pageswap', function(e) {
    if (!e.viewTransition) return;
    var type = 'forwards';
    if (e.activation && e.activation.navigationType === 'traverse') {
      var fromIndex = e.activation.from && e.activation.from.index;
      var toIndex = e.activation.entry && e.activation.entry.index;
      if (toIndex < fromIndex) type = 'backwards';
    }
    e.viewTransition.types.add(type);
    sessionStorage.setItem('viewTransitionType', type);
  });

  window.addEventListener('pagereveal', function(e) {
    if (!e.viewTransition) return;
    var type = sessionStorage.getItem('viewTransitionType') || 'forwards';
    e.viewTransition.types.add(type);
  });
})();

For the animation itself, mobile got a directional slide plus fade, desktop kept the browser's default crossfade and just had its duration tuned:

@keyframes fade-in {
  from { opacity: 0; }
}
@keyframes fade-out {
  to { opacity: 0; }
}
@keyframes slide-from-right {
  from { transform: translateX(300px); }
}
@keyframes slide-to-left {
  to { transform: translateX(-300px); }
}
@keyframes slide-from-left {
  from { transform: translateX(-300px); }
}
@keyframes slide-to-right {
  to { transform: translateX(300px); }
}

/* Mobile: short slide + fade */
@media (--mobile-only) {
  ::view-transition-old(root) {
    animation: fade-out 0.3s cubic-bezier(0.4, 0, 1, 1) both,
      slide-to-left 0.3s cubic-bezier(0.4, 0, 0.2, 1) both;
  }
  ::view-transition-new(root) {
    animation: fade-in 0.7s cubic-bezier(0, 0, 0.2, 1) 90ms both,
      slide-from-right 0.7s cubic-bezier(0.4, 0, 0.2, 1) both;
  }

  /* going "back": mirror the slide direction */
  :root:active-view-transition-type(backwards) {
    &::view-transition-old(root) {
      animation-name: fade-out, slide-to-right;
    }
    &::view-transition-new(root) {
      animation-name: fade-in, slide-from-left;
    }
  }
}

/* Desktop: crossfade only, no slide */
@media (--tablet-desktop) {
  ::view-transition-group(root) {
    animation-duration: 0.6s;
  }
}

What we found

Variant AdViews vs A LCP median vs A
A (control) reference 578ms (baseline)
B (prefetch only) Not Significant -83.5ms (-86.01ms; -81.21ms)
C (transition only) -1.87% (-2.89%; -0.85%) +28ms (25.32ms; 30.40ms)
D (both) -1.72% (-2.77%; -0.67%) -53ms (-55.49ms; -50.58ms)

Roughly 4.5M eligible users went through the test:

  • Variant B was a clean win on speed, with meaningfully faster TTFB and LCP, but no statistically significant impact on AdViews either way.
  • Variants C and D both showed a significant drop in AdViews, our primary metric, of around 1.8%. C, the transition-only variant, was also a touch slower on LCP than the control, not faster. The animation we added to make navigation feel more fluid was associated with fewer AdViews, and in C it also came with slower rendering.
  • B and D generated extra prefetch requests per eligible user compared to control, and that showed up on our infrastructure: with only 50% of traffic in the experiment, our Kubernetes pod count went from around 32 to 40–42, about 8–10 extra pods to absorb the additional prefetch load.

The decision

Speculation Rules

We didn't ship the speculation Rules; it's faster with no downside on AdViews, but we're not fast-tracking it either. It costs extra prefetch requests at scale, and before turning that on for 100% of traffic we want an explicit infrastructure-cost conversation.

We already got a preview of what that looks like: early in the experiment we ramped to 100% of traffic and our backend visibly felt the extra pressure, so we scaled back to 50% for the rest of the run, and even at 50% we needed 8–10 extra Kubernetes pods to keep up.

View Transition

We didn't ship the View Transition. Twice we told ourselves the animation was probably fine and the metric would recover with a bit of tuning, and twice the data said otherwise, so we stopped arguing with it.

That doesn't mean view transitions are inherently bad, but a feature that looks purely additive, smoother animation, nothing lost, can have a real, measurable cost if it adds even a small amount of latency or visual delay in front of a conversion-critical action. On a page already rendering in under 80ms, that margin was thin enough for a 28ms LCP regression to show up in the primary business metric.

We might revisit the animation itself, a different duration, a different easing, maybe none at all on the first paint, because this result tells us this specific implementation didn't work, not that the idea can never work.

πŸ“° Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.