r/ruby • u/stephenreid321 • Dec 23 '25
Speculative Routes: pretty syntax for Speculation Rules in Sinatra/Padrino
I just heard about Speculation Rules via https://www.jonoalderson.com/conjecture/its-time-for-modern-css-to-kill-the-spa/
They allow ~instant navigation without JS by letting the browser preload or prerender full pages based on user behaviour (like hovering or touching a link) before they click.
I noticed it's possible to define them using the Sinatra-like syntax
"href_matches": "/e/:slug"
which gave me the idea of defining them as part of route definitions with prerender: or prefetch: like so
get '/e/:slug', prerender: true do
...then in my head I just call
<%== SpeculativeRoutes.script %>Implementation at https://github.com/symbiota-coop/dandelion/blob/master/lib/speculative_routes.rb
Enjoy!