v1.6.2
Trade Portal — Automatic asset cache-busting
🇬🇧 English
Why
Every time TradePortal.js, TradePortal.css, or TradePortal.html changed, users (and Cloudflare) kept serving the stale cached version. New features (tooltips, toast, Poké Ball backgrounds, etc.) would silently fail to appear until someone did a manual Cloudflare purge + browser hard refresh.
What changed
- Content-hashed asset version token. On server start,
BotServernow computes a single SHA-1 hash (first 10 hex chars) over the combined bytes of the embeddedTradePortal.js,TradePortal.css, andTradePortal.html. This value is cached for the process lifetime under a thread-safe lazy initializer — zero per-request overhead. - HTML token replacement.
TradePortal.htmlnow references its sibling assets via a__ASSET_VER__placeholder:A new helper<link rel="stylesheet" href="/TradePortal.css?v=__ASSET_VER__"> <script src="/TradePortal.js?v=__ASSET_VER__" type="module"></script>
LoadTradePortalHtml()substitutes the placeholder with the liveAssetVersionon every/traderequest, and the route now goes through it. - Graceful fallback. If hashing the embedded resources fails for any reason, the version falls back to a timestamp-based token (
DateTime.UtcNow.Ticksin hex) so cache-busting still works.
Result
- Every rebuild → new content → new hash → new asset URL → Cloudflare and browsers fetch fresh JS/CSS automatically.
- No more manual Cloudflare purges or
Ctrl+Shift+Rafter deploying. - Existing Cloudflare allowlist rules still work —
http.request.uri.pathdoes not include the query string, so/TradePortal.css?v=abcstill matcheseq "/TradePortal.css". - HTML keeps its
Cache-Control: no-cache(correct, since it's the entry point that carries the new token); JS/CSS can safely live in the edge cache forever because their URL changes whenever their content does.
New developer workflow
- Edit
TradePortal.{js,css,html} - Rebuild
- Restart the bot
- Users see the change on next page load — no purge, no hard refresh
🇪🇸 Español
Por qué
Cada vez que cambiaban TradePortal.js, TradePortal.css o TradePortal.html, los usuarios (y Cloudflare) seguían sirviendo la versión vieja desde caché. Funcionalidades nuevas (tooltips, toast, fondo con Pokébolas, etc.) no aparecían hasta hacer purge manual en Cloudflare + hard refresh en el navegador.
Qué cambió
- Token de versión basado en hash del contenido. Al arrancar el servidor,
BotServercalcula una sola vez un hash SHA-1 (primeros 10 caracteres hex) sobre los bytes combinados de los recursos embebidosTradePortal.js,TradePortal.cssyTradePortal.html. El valor se cachea durante toda la vida del proceso con un lazy initializer thread-safe — cero overhead por petición. - Sustitución de token en el HTML.
TradePortal.htmlahora referencia sus assets hermanos con un placeholder__ASSET_VER__:Un nuevo helper<link rel="stylesheet" href="/TradePortal.css?v=__ASSET_VER__"> <script src="/TradePortal.js?v=__ASSET_VER__" type="module"></script>
LoadTradePortalHtml()sustituye el placeholder por elAssetVersionreal en cada petición a/trade, y la ruta ahora pasa por ahí. - Fallback elegante. Si el hash falla por cualquier razón, la versión cae a un token basado en timestamp (
DateTime.UtcNow.Ticksen hex), garantizando que el cache-busting siga funcionando.
Resultado
- Cada rebuild → contenido nuevo → hash nuevo → URL nueva → Cloudflare y navegadores descargan JS/CSS frescos automáticamente.
- Adiós a purgar manualmente Cloudflare o pulsar
Ctrl+Shift+Rdespués de cada deploy. - Las reglas existentes de Cloudflare siguen funcionando —
http.request.uri.pathno incluye la query string, así que/TradePortal.css?v=abcsigue matcheandoeq "/TradePortal.css". - El HTML mantiene su
Cache-Control: no-cache(correcto, ya que es el entry point que lleva el token nuevo); JS/CSS pueden vivir indefinidamente en la caché del edge porque su URL cambia cuando su contenido cambia.
Nuevo flujo de trabajo
- Editas
TradePortal.{js,css,html} - Rebuild
- Reinicias el bot
- Los usuarios ven el cambio al recargar — sin purge, sin hard refresh