From b5002d7ce67273e4627918efcd749ee793e9ce14 Mon Sep 17 00:00:00 2001 From: ryanbr Date: Tue, 7 Apr 2026 10:32:15 +1200 Subject: [PATCH] Cache getWasmWorkerJs result to avoid redundant synchronous XHR Stores fetched worker blob text by URL. Cache hit skips the blocking synchronous XHR on subsequent calls with the same blob URL. Co-Authored-By: Claude Opus 4.6 (1M context) --- vaft/vaft-ublock-origin.js | 10 +++++++++- vaft/vaft.user.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/vaft/vaft-ublock-origin.js b/vaft/vaft-ublock-origin.js index f927c53..c16bbea 100644 --- a/vaft/vaft-ublock-origin.js +++ b/vaft/vaft-ublock-origin.js @@ -255,11 +255,19 @@ twitch-videoad.js text/javascript }); } function getWasmWorkerJs(twitchBlobUrl) { + if (!getWasmWorkerJs.cache) { + getWasmWorkerJs.cache = Object.create(null); + } + if (getWasmWorkerJs.cache[twitchBlobUrl]) { + return getWasmWorkerJs.cache[twitchBlobUrl]; + } const req = new XMLHttpRequest(); req.open('GET', twitchBlobUrl, false); req.overrideMimeType("text/javascript"); req.send(); - return req.responseText; + const text = req.responseText; + getWasmWorkerJs.cache[twitchBlobUrl] = text; + return text; } // Hook fetch() in the worker scope to intercept m3u8 playlist requests and ad segments function hookWorkerFetch() { diff --git a/vaft/vaft.user.js b/vaft/vaft.user.js index 1066138..82a2760 100644 --- a/vaft/vaft.user.js +++ b/vaft/vaft.user.js @@ -266,11 +266,19 @@ }); } function getWasmWorkerJs(twitchBlobUrl) { + if (!getWasmWorkerJs.cache) { + getWasmWorkerJs.cache = Object.create(null); + } + if (getWasmWorkerJs.cache[twitchBlobUrl]) { + return getWasmWorkerJs.cache[twitchBlobUrl]; + } const req = new XMLHttpRequest(); req.open('GET', twitchBlobUrl, false); req.overrideMimeType("text/javascript"); req.send(); - return req.responseText; + const text = req.responseText; + getWasmWorkerJs.cache[twitchBlobUrl] = text; + return text; } // Hook fetch() in the worker scope to intercept m3u8 playlist requests and ad segments function hookWorkerFetch() {