wowtoken.app

git clone https://git.emily.sh/wowtoken-app/wowtoken.app.git
Log | Files | Refs | README | LICENSE

commit fa60c3ea534faf4288e748a42967dbed9f905a84
parent 1e0b4a0a1f43326e5ca6d8f2c194772337f28f32
Author: Emily Doherty <git@emily.sh>
Date:   Sun, 26 May 2024 11:38:51 -0700

Add early reply header to first requests

This lets my CloudFront function know whether to serve a request from the Lambda@edge function with more body, or an early request from the Cloudfront KeyValueStore. This is an A/B test with retail vs classic site at the time of commit

Diffstat:
Msrc/index.html | 2+-
Msrc/index.js | 9++++++++-
2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/index.html b/src/index.html @@ -7,7 +7,7 @@ <meta name="description" content="Track current and historical gold price trends for the World of Warcraft (WoW) in game token, including the US, EU, TW, and KR regions. Prices updated every minute. Simple, quick, and easy info, no ads or tracking, ever."> <link rel="preconnect" href="https://data.wowtoken.app"> <link rel="dns-prefetch" href="https://data.wowtoken.app"> - <link rel="preload" href="https://data.wowtoken.app/token/current.json" as="fetch" type="application/json" crossorigin="anonymous"> + <link rel="preload" href="https://data.wowtoken.app/token/current.json?kv-response=true" as="fetch" type="application/json" crossorigin="anonymous"> <link rel="preload" href="https://data.wowtoken.app/token/history/us/72h.json" as="fetch" type="application/json" crossorigin="anonymous"> </head> <body> diff --git a/src/index.js b/src/index.js @@ -29,6 +29,7 @@ let currentRegionSelection = ''; let currentTimeSelection = ''; let currentAggregateSelection = ''; let startYAtZero = false; +let firstLoad = true; const currentPriceHash = { us: 0, eu: 0, @@ -124,7 +125,13 @@ function lookupTimeUnit(query){ async function callUpdateURL() { - let resp = await fetch("https://data.wowtoken.app/token/current.json"); + let url = "https://data.wowtoken.app/token/current.json" + if (firstLoad) { + url = `${url}?kv-response=true`; + firstLoad = false; + } + + let resp = await fetch(url); let data = await resp.json(); updateTokens(data); }