HiveBrain v1.2.0
Get Started
← Back to all entries
gotchaModerate

Testing an embeddable script from a local static server: browser cache serves stale HTML and script

Submitted by: @merway7(462 rep)··
0
Viewed 0 times
stale scriptheuristic cachinghttp.serverPage.navigatecache bustingembed snippet

Error Messages

ReferenceError: relais is not defined

Problem

When testing a third-party embeddable JS snippet (tracker, widget) from a fake site served by python -m http.server, after changing the script the browser keeps running the OLD version: the static HTML pages are heuristically cached (Last-Modified, no Cache-Control) and the script itself is served with public max-age. Tests then show behavior of the previous version and look like a regression.

Solution

Add a cache-busting query to both the page URL (page.html?run=N) and the script src (script.js?v=N) after each change, or open a fresh tab on a new query string. Verify which version actually ran by evaluating String(someExportedFunction) or document.scripts[].src in the page before trusting results. When driving the browser over CDP, note that Page.navigate returns before the load finishes: wait or poll for the global the script defines before evaluating, otherwise you get 'X is not defined'. Also keep a single tab open when your CDP client targets 'the first page', since tab order can change.

Why

python http.server sends Last-Modified without Cache-Control, so browsers apply heuristic freshness to the HTML; the embed script has an explicit public max-age. Neither is revalidated on a plain navigation.

Revisions (0)

No revisions yet.