Skip to content

transitlos.map.buildstamp

Build stamp for every published map page.

stamp_html writes a <meta name="build-id"> plus a small guard script into a map page. On load (and when the tab becomes visible again) the guard fetches the small sidecar <page>.build (written next to the page, cache: 'no-store') and compares the build id: when the published page is newer than the one running, it deletes the Cache Storage / service workers, re-downloads the page bypassing the HTTP cache and reloads once. The stamp is idempotent (a second call replaces the first), so it can be applied to freshly built pages and to already deployed ones.

build_id(html)

Content hash of the page without its stamp: unchanged pages keep their id, any change gives a new one.

Parameters:

Name Type Description Default
html str

Page HTML.

required

Returns:

Type Description
str

12-character id.

stamp_html(html, name='map.html', date=None)

(stamped html, build id): the stamp sits right after <head> and replaces an earlier one.

Parameters:

Name Type Description Default
html str

Page HTML.

required
name str

File name written in the stamp.

'map.html'
date str | None

Build date; None = today.

None

data_marker(html, page_path)

Puts a hash of the page's small data files (results/*.json|geojson|js: stats, area outlines and masks, vehicle-km, column info ...) into the page as a comment, so the build id changes whenever that data changes even when the page itself does not. Data requested with ?v=<build id> is cached for a year: without this a changed data file could be shadowed by an older copy cached under an unchanged id. Pages without a results folder are left alone.

Parameters:

Name Type Description Default
html str

Page HTML.

required
page_path

Path of the page.

required

Returns:

Type Description
str

The HTML with the data marker.

externalize_stats(html, page_path)

Moves the inline window.__statsData = {...} (tens of MB on the big cities) to results/stats_data.js, loaded by a plain script tag whose URL carries the content hash: the page shrinks, the browser fetches the data in parallel and keeps it (immutable) across visits. Pages without the inline block, or without a results folder, are unchanged.

Parameters:

Name Type Description Default
html str

Page HTML.

required
page_path

Path of the page.

required

Returns:

Type Description
str

The HTML (shorter when the data were moved).

write_stamped(path, html)

Writes the stamped page and its <page>.build sidecar (the build id, fetched by the guard); returns the id.

Parameters:

Name Type Description Default
path

Page path.

required
html str

Page HTML.

required

stamp_file(path)

Stamps an already written page in place (idempotent); rewrites nothing when the page and its sidecar are current.

Parameters:

Name Type Description Default
path

Page path.

required

Returns:

Type Description
str

The build id.