{"id":8804,"date":"2026-11-24T10:14:38","date_gmt":"2026-11-24T10:14:38","guid":{"rendered":"https:\/\/webcode.tools\/insights\/?p=8804"},"modified":"2026-11-24T10:14:38","modified_gmt":"2026-11-24T10:14:38","slug":"building-a-live-odds-board-for-horse-racing-handling-fast-changing-data-without-breaking-the-page","status":"publish","type":"post","link":"https:\/\/webcode.tools\/insights\/building-a-live-odds-board-for-horse-racing-handling-fast-changing-data-without-breaking-the-page\/","title":{"rendered":"Building a Live Odds Board for Horse Racing: Handling Fast-Changing Data Without Breaking the Page"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1280\" height=\"853\" src=\"https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page.jpg\" alt=\"Building a Live Odds Board for Horse Racing Handling Fast-Changing Data Without Breaking the Page\" class=\"wp-image-8806\" style=\"aspect-ratio:1.502145922746781;width:700px;height:auto\" srcset=\"https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page.jpg 1280w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page-300x200.jpg 300w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page-1024x682.jpg 1024w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page-768x512.jpg 768w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page-150x100.jpg 150w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page-450x300.jpg 450w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Building-a-Live-Odds-Board-for-Horse-Racing-Handling-Fast-Changing-Data-Without-Breaking-the-Page-1200x800.jpg 1200w\" sizes=\"(max-width: 1280px) 100vw, 1280px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">A live odds board comes with plenty of challenges, and the design isn\u2019t the main one. First of all, it presents a lot of information, which should be readable and understandable by users.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\"> On top of that, there are many processes that run in the background. The prices change, the rows move around, and suddenly you\u2019re reading about a different horse from the one you started with.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">So, the goal is to build a live odds board that updates automatically without any layout shifts that might ruin the user experience.&nbsp;<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Start With a Price Change You Can Follow<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Horse racing live odds boards have a lot of data, especially for popular events. When building around the <\/span><a href=\"https:\/\/www.twinspires.com\/kentuckyderby\/contenders\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">2027 Kentucky Derby contenders<\/span><\/a><span style=\"font-weight: 400;\">, each horse needs an identity that survives a price change.&nbsp;<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The board needs a solid fundation. If you\u2019re listing Sample A above Sample B, the price change might flip their order. In other words, if you update rows by position, this could put Sample B\u2019s price beside Sample A. <\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">So make sure you match prices to permanent runner IDs instead. Each of the 2027 Kentucky Derby contenders should have a unique ID.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Here, the race is sample-race, with runners a and b. Treat version as an update number and increase it whenever you edit the data.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The page should accept version two after version one, then ignore version one if it arrives late. All names and prices below are fictional.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Save this as <\/span><span style=\"font-weight: 400;\">odds.json<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n\n\u00a0\u00a0\"raceId\": \"sample-race\", \"version\": 1, \"state\": \"open\",\n\n\u00a0\u00a0\"runners\": &#91;\n\n\u00a0\u00a0\u00a0\u00a0{\"id\": \"a\", \"odds\": \"5\/1\"},\n\n\u00a0\u00a0\u00a0\u00a0{\"id\": \"b\", \"odds\": \"9\/2\"}\n\n\u00a0\u00a0]\n\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Get The Polling Version Working<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Save the following as <\/span><span style=\"font-weight: 400;\">index.html<\/span><span style=\"font-weight: 400;\"> beside that file. With Python installed, run <\/span><span style=\"font-weight: 400;\">python -m http.server 8000 &#8211;bind 127.0.0.1<\/span><span style=\"font-weight: 400;\"> from the folder, using<\/span> <a href=\"https:\/\/docs.python.org\/3\/library\/http.server.html#command-line-interface\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Python&#8217;s local server<\/span><\/a><span style=\"font-weight: 400;\">, then open <\/span><span style=\"font-weight: 400;\">http:\/\/127.0.0.1:8000<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!doctype html>\n\n&lt;html lang=\"en\">\n\n&lt;meta charset=\"utf-8\">\n\n&lt;meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n\n&lt;title>Sample odds&lt;\/title>\n\n&lt;style>\n\n\u00a0\u00a0table { width:100%; table-layout:fixed; }\n\n\u00a0\u00a0thead th:last-child { width:8ch; }\n\n\u00a0\u00a0td { text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; }\n\n\u00a0\u00a0#connection, #summary { min-height:3em; }\n\n&lt;\/style>\n\n&lt;table>\n\n\u00a0\u00a0&lt;caption>Sample fractional win odds&lt;\/caption>\n\n\u00a0\u00a0&lt;thead>&lt;tr>&lt;th scope=\"col\">Runner&lt;\/th>&lt;th scope=\"col\">Odds&lt;\/th>&lt;\/tr>&lt;\/thead>\n\n\u00a0\u00a0&lt;tbody>\n\n\u00a0\u00a0\u00a0\u00a0&lt;tr>&lt;th scope=\"row\">Sample A&lt;\/th>&lt;td data-id=\"a\">\u2014&lt;\/td>&lt;\/tr>\n\n\u00a0\u00a0\u00a0\u00a0&lt;tr>&lt;th scope=\"row\">Sample B&lt;\/th>&lt;td data-id=\"b\">\u2014&lt;\/td>&lt;\/tr>\n\n\u00a0\u00a0&lt;\/tbody>\n\n&lt;\/table>\n\n&lt;button id=\"pause\" type=\"button\">Pause prices&lt;\/button>\n\n&lt;p id=\"connection\">&lt;\/p>\n\n&lt;p id=\"summary\" aria-live=\"polite\" aria-atomic=\"true\">&lt;\/p>\n\n&lt;script>\n\nconst cells = new Map(&#91;...document.querySelectorAll('&#91;data-id]')]\n\n\u00a0\u00a0.map(cell => &#91;cell.dataset.id, cell]));\n\nconst button = document.querySelector('#pause');\n\nconst connection = document.querySelector('#connection');\n\nconst summary = document.querySelector('#summary');\n\nlet latest = null, paused = false, closed = false, delay = 3000;\n\nlet changedAt = '', pending = new Set();\n\n\u00a0\n\nfunction draw(s) {\n\n\u00a0\u00a0for (const r of s.runners) {\n\n\u00a0\u00a0\u00a0\u00a0const cell = r &amp;&amp; cells.get(r.id);\n\n\u00a0\u00a0\u00a0\u00a0if (cell &amp;&amp; typeof r.odds === 'string' &amp;&amp; cell.textContent !== r.odds) {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cell.textContent = r.odds;\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0pending.add(r.id);\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0changedAt = new Date().toLocaleTimeString();\n\n\u00a0\u00a0\u00a0\u00a0}\n\n\u00a0\u00a0}\n\n}\n\nfunction accept(s) {\n\n\u00a0\u00a0if (s.raceId !== 'sample-race' || !Number.isSafeInteger(s.version)\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0|| !Array.isArray(s.runners)) throw new Error('Invalid snapshot');\n\n\u00a0\u00a0if (latest &amp;&amp; s.version &lt;= latest.version) return;\n\n\u00a0\u00a0latest = s;\n\n\u00a0\u00a0closed = s.state === 'closed';\n\n\u00a0\u00a0if (!paused) draw(s);\n\n}\n\nasync function poll() {\n\n\u00a0\u00a0try {\n\n\u00a0\u00a0\u00a0\u00a0const response = await fetch('odds.json', {\n\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0cache:'no-store', signal:AbortSignal.timeout(5000)\n\n\u00a0\u00a0\u00a0\u00a0});\n\n\u00a0\u00a0\u00a0\u00a0if (!response.ok) throw new Error('Fetch failed');\n\n\u00a0\u00a0\u00a0\u00a0accept(await response.json());\n\n\u00a0\u00a0\u00a0\u00a0connection.textContent = closed ? 'Updates closed' : 'Connected';\n\n\u00a0\u00a0\u00a0\u00a0delay = 3000;\n\n\u00a0\u00a0} catch {\n\n\u00a0\u00a0\u00a0\u00a0connection.textContent = 'Updates delayed; keeping previous prices.';\n\n\u00a0\u00a0\u00a0\u00a0delay = Math.min(delay * 2, 30000);\n\n\u00a0\u00a0}\n\n\u00a0\u00a0if (!closed) setTimeout(poll, delay);\n\n}\n\nbutton.onclick = () => {\n\n\u00a0\u00a0paused = !paused;\n\n\u00a0\u00a0button.textContent = paused ? 'Resume prices' : 'Pause prices';\n\n\u00a0\u00a0pending.clear();\n\n\u00a0\u00a0if (!paused &amp;&amp; latest) draw(latest);\n\n};\n\nsetInterval(() => {\n\n\u00a0\u00a0if (!paused &amp;&amp; pending.size) {\n\n\u00a0\u00a0\u00a0\u00a0const n = pending.size;\n\n\u00a0\u00a0\u00a0\u00a0summary.textContent = `${n} runner${n === 1 ? '' : 's'} updated at ${changedAt}.`;\n\n\u00a0\u00a0\u00a0\u00a0pending.clear();\n\n\u00a0\u00a0}\n\n}, 10000);\n\npoll();\n\n&lt;\/script>\n\n&lt;\/html><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">So, the next request starts after the previous one finishes, following<\/span> <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/setInterval#ensure_that_execution_duration_is_shorter_than_interval_frequency\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">MDN&#8217;s polling guidance<\/span><\/a><span style=\"font-weight: 400;\">. Errors leave the previous prices visible and increase the retry delay. Setting <\/span><span style=\"font-weight: 400;\">state<\/span><span style=\"font-weight: 400;\"> to <\/span><span style=\"font-weight: 400;\">closed<\/span><span style=\"font-weight: 400;\"> in a newer snapshot stops polling.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Stop the Numbers From Moving the Page<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Here&#8217;s a surprisingly annoying problem that\u2019s quite easy to solve. A value changes from <\/span><span style=\"font-weight: 400;\">9.8<\/span><span style=\"font-weight: 400;\"> to <\/span><span style=\"font-weight: 400;\">10.2<\/span><span style=\"font-weight: 400;\">, the text becomes wider, and the layout moves.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">That&#8217;s exactly the kind of thing<\/span> <a href=\"https:\/\/web.dev\/articles\/optimize-cls\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Google&#8217;s layout-shift guidance<\/span><\/a><span style=\"font-weight: 400;\"> recommends avoiding.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">You can test this yourself by opening the demo and watching how the table behaves when prices change. <\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Pay attention to whether the rows move, especially when a number changes from something short like 8.5 to something longer like 12.75.<\/span><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" width=\"1240\" height=\"942\" src=\"https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page.png\" alt=\"Stop the Numbers From Moving the Page\" class=\"wp-image-8805\" style=\"aspect-ratio:1.3157894736842106;width:700px;height:auto\" srcset=\"https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page.png 1240w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page-300x228.png 300w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page-1024x778.png 1024w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page-768x583.png 768w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page-150x114.png 150w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page-450x342.png 450w, https:\/\/webcode.tools\/insights\/wp-content\/uploads\/2026\/11\/Stop-the-Numbers-From-Moving-the-Page-1200x912.png 1200w\" sizes=\"(max-width: 1240px) 100vw, 1240px\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Don&#8217;t Make Screen Readers Narrate Every Number<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Everything is easy to understand on paper, but that\u2019s only when we compare two rows or two horses. <\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The real problem starts when most of the horses&#8217; prices get updated every three seconds, while a screen reader tries to announce every change.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">It becomes a total mess.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">Instead of announcing every individual update, the example uses an aria-live=&#8221;polite&#8221; region to provide summaries every ten seconds. <\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">This prevents the screen reader from constantly interrupting the user while still providing information about changes.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The Pause Prices button also stops visible updates and announcements, but incoming data continues to be cached in the background.<\/span><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span style=\"font-weight: 400;\">Final Thoughts<\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">So, building a live odds board isn&#8217;t really about changing numbers quickly. That&#8217;s the easy part.<\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-weight: 400;\">The difficult part is keeping the page readable and the information current without annoying everyone watching it. And fortunately, you can work most of that out with fictional data before connecting a real feed.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A live odds board comes with plenty of challenges, and the design isn\u2019t the main one. First of all, it presents a lot of information, which should be readable and understandable by users. On top of that, there are many processes that run in the background. The prices change, the rows move around, and suddenly<\/p>\n","protected":false},"author":1,"featured_media":8806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[],"class_list":["post-8804","post","type-post","status-publish","format-standard","has-post-thumbnail","category-insights"],"_links":{"self":[{"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/posts\/8804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/comments?post=8804"}],"version-history":[{"count":3,"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/posts\/8804\/revisions"}],"predecessor-version":[{"id":8810,"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/posts\/8804\/revisions\/8810"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/media\/8806"}],"wp:attachment":[{"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/media?parent=8804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/categories?post=8804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webcode.tools\/insights\/wp-json\/wp\/v2\/tags?post=8804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}