Skip to content

Allow disabling automatic web font loading - #1564

Open
pjeweb wants to merge 1 commit into
openlayers:mainfrom
pjeweb:feat/disable-webfonts
Open

pjeweb wants to merge 1 commit into
openlayers:mainfrom
pjeweb:feat/disable-webfonts

Conversation

@pjeweb

@pjeweb pjeweb commented Oct 29, 2026 •

Copy link
Copy Markdown

Closes #1563.

Currently

When a font in a style's text-font is not available, ol-mapbox-style loads a stylesheet for it from Fontsource on jsDelivr. Applications can redirect or reduce these requests, but not turn them off:

  • The style publisher points ol:webfonts to fonts it hosts, as the README describes. basemap.de, for example, does not do this yet.
  • The application points the webfonts option to its own server. Every face it does not host is still requested there and fails with a 404, once per face and page load.
  • The application loads the style's fonts with CSS, or rewrites the style's text-font values to fonts it already has. A face that a style update adds or renames is then fetched from the CDN again.

Wanted

A switch that lets an application turn automatic font loading off:

  • Labels use the fonts the page provides.
  • No font requests are made, so none go to third parties and none are expected to fail with a 404.
  • Nothing has to be kept in sync when the style changes.

Implemented Change

With webfonts: false passed to apply() or applyStyle():

  • ol-mapbox-style adds no font stylesheets.
  • Labels use the fonts the page provides, including any the application mapped by rewriting text-font.
  • Faces the page does not provide use the browser's default font. This also holds for faces that a later style update adds or renames.
  • Styles with ol:webfonts metadata are the exception: their fonts still load from that location.

Without the option, nothing changes, so maps keep their intended fonts.

@ahocevar ahocevar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address my inline comments, and simplify the tests accordingly, avoiding test bloat.

Comment thread README.md Outdated
Comment on lines +102 to +103
fonts use the browser's fallback. A style can also set `metadata['ol:webfonts']` to `false` to
disable automatic loading for that style.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not support metadata['ol:webfonts'] set to false.

Comment thread src/apply.js Outdated
getFonts(fonts, templateUrl),
getFonts(
fonts,
options.webfonts === false ? false : templateUrl,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templateUrl already has the value of options.webfonts here, so this change is not necessary.

@pjeweb
pjeweb force-pushed the feat/disable-webfonts branch from 2d871dd to 769214d Compare November 2, 2026 00:23
@pjeweb

pjeweb commented Nov 2, 2026 •

Copy link
Copy Markdown
Author

I removed the metadata opt-out and redundant apply.js logic, rebased onto main, reduced the tests to one case, and rewrote the description.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow disabling automatic web font loading

2 participants