Incremental Font Transfer via Range Request

W3C First Public Working Draft,

More details about this document
This version:
https://www.w3.org/TR/2022/WD-RangeRequest-20220125/
Latest published version:
https://www.w3.org/TR/RangeRequest/
Editor's Draft:
https://w3c.github.io/IFT/RangeRequest.html
History:
https://www.w3.org/standards/history/RangeRequest
Feedback:
public-webfonts-wg@w3.org with subject line “[RangeRequest] … message topic …” (archives)
GitHub
Inline In Spec
Editors:
Chris Lilley (W3C)
(Apple Inc.)
(Google Inc.)

Abstract

Specification for incremental font transfer via HTTP range requests.

Status of this document

This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

This document was produced by the Web Fonts Working Group as a First Public Working Draft using the Recommendation track.

If you wish to make comments regarding this document, please file an issue on the specification repository.

This document is a First Public Working Draft.

Publication as a First Public Working Draft does not imply endorsement by W3C and its Members. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 2 November 2021 W3C Process Document.

1. Introduction

This section is not normative.

Incremental Font Transfer (IFT) is a collection of technologies to improve the latency of remote fonts (or "web fonts") on the web. Without this technology, a browser needs to download every last byte of a font before it can render any characters using that font. IFT allows the browser to download only some of the bytes in the file, thereby decreasing the perceived latency between the time when a browser realizes it needs a font and when the necessary text can be rendered with that font.

There are two technologies inside the IFT collection of technologies. This document describes one of them: the "Range-request method." In this method, the browser uses HTTP range requests to download only specific regions of the font file that it needs. In order for this method to be as effective as possible, the font file itself should be arranged in a particular way, in order to decrease the number of requests the browser needs to make.

The range-request IFT method has best performance on Chinese, Japanese, and Korean languages. These languages usually have the largest font files, and usually include many glyphs which are generally independent.

The range-request method was designed to be as easy as possible to deploy, and doesn’t require any server-side software. Deploying this method involves two steps:

  1. Modifying the CSS of the webpage to opt-in, by adding a particular keyword to particular places in the CSS file, and

  2. Optionally, rearranging the data inside the font file to optimize loading performance. This rearrangement process is a process by which a valid font file is input to the process and a valid font file is output from the process. When being served, the optimized font simply replaces the unoptimized font on the server. Every step in the optimization process is optional, but each should improve performance if performed. The optimization process is lossless, and no contours are affected.

A rearranged font file is still a valid font file following existing formats; this specification does *not* describe a new font file format. The guidelines simply list strategies for organizing the data within the file to achieve the best performance with the range request method.

2. Opt-In Mechanism

This section is general to both IFT methods, and is not specific to the range-request method.

The collection of IFT technologies utilizes a single shared opt-in mechanism. Each method does not use its own opt-in mechanism; instead, the webpage opts into the IFT technologies as a whole, and the browser and server negotiate to decide which specific method will be employed.

The opt-in mechanism is the incremental keyword inside the @font-face block. Websites specify this keyword inside their @font-face block, and the browser is then responsible for using IFT technologies, and for negotiating with the server to determine which specific IFT method to use.

The use of the incremental keyword in this CSS rule indicates to the browser they should use IFT.
@font-face {
    font-family: "MyCoolWebFont";
    src: url("MyCoolWebFont.otf") tech(incremental);
}

Note: Each individual @font-face block may or may not opt-in to IFT. This is due to the variety of ways fonts are used on web pages. Authors have control over which fonts they want to use this technology with, and which they do not.

3. IFT Method Selection

This section is general to both IFT methods, and is not specific to the range-request method.

When a page has indicated that a particular font should utilize IFT technology, the browser must determine which method to use. Different browsers may support different IFT methods, and different servers may support different IFT methods, so a negotation occurs as such:

  1. The browser makes the first request to the server. If the client prefers the patch-subset method, it sends the relevant query parameter. If the client prefers the range-request method, it does not send the query parameter.

  2. If the server receives the patch-subset query parameter and wishes to honor it, the server may reply with a valid patch subset response which includes the patch-subset magic number. Otherwise, the server may reply with the [RFC7233] Accept-Ranges header.

  3. If the client receives the patch-subset magic number, it commences using the patch-subset method. Otherwise, if the client receives the Accept-Ranges: bytes header, it commences using the range-request method. Otherwise, the whole font file is downloaded, and the current non-incremental loading behavior is used.

3.1. IFT Method Fallback

This section is not normative.

This summarizes behaviors that result from the above method selection.

Client prefers range-request method Client prefers patch-subset method
Server supports both range-request method and patch-subset method Client makes initial request without query parameter, and possibly with the Range header. Because all patch-subset servers must support the range-request method, the server replies with Accept-Ranges and initial font data. Client/server commence using range-request method.

Server-recommended IFT Method selection

Client makes initial request with query parameter. Server replies with the patch-subset magic number, and client/server commence using patch-subset method.
Server supports only range-request method Same as above. Client makes initial request with query parameter. Server replies with Accept-Ranges and initial font data. Client/server commence using range-request method.
Server supports neither Client makes initial request without query parameter, and possibly with the Range header. Server replies without Accept-Ranges header, and sends the full font file to the client from beginning to end. Client makes initial request to server with query parameter. Server does not reply with the patch-subset magic number, and sends the full font file to the client from beginning to end.

4. Font organization

4.1. Background

This section is not normative.

A particular organization of font files is beneficial for improving the performance of the range-request IFT method. The range-request IFT method only works with [TRUETYPE], [OPENTYPE], [WOFF], or [WOFF2] files. All of these file formats use an sfnt wrapper which provides a directory of tables inside the font file. A sfnt-based font file is mainly composed of a collection of independent tables.

Using WOFF2 files with range-request mechanism doesn’t seem to be a viable option

4.2. Introduction

The term range-request optimized font is used to describe a font file organized for use with the range-request IFT method. Optimizing a font for the range-request IFT method does not change the file format of the font.

Note: Because optimizing a font does not change its file format, no new additional tooling is necessary to interact with these optimized fonts. They are still valid fonts, but with a particular internal organization.

The result of optimizing an OpenType font for the range-request IFT method is still a valid OpenType font. The resulting file may be larger (by byte count) than it was before optimizing it, but fewer of those bytes should be necessary for a client to download in order to render a target text.

Note: There are no MUST-level requirements on the organization of a range-request optimized font. Any arbitrary font file may be considered to be a range-request optimized font. However, additional optimizations should increase the performance of loading in a browser via the range-request IFT method. Font creators are encouraged to enact as many of the optimizations listed in this section as are reasonable for the fonts they create.

4.3. Compression

Servers supporting the range-request IFT method should support compression via the [RFC7231] Content-Encoding header or the [RFC7230] Transfer-Encoding header, rather than having the font file itself be statically compressed.

A range-request optimized font file (the file itself) should not use any kind of compression other than [RFC7932] (commonly referred to as "Brotli") compression.

If Brotli compression is used in a range-request optimized font, it should use only one meta-block.

If Brotli compression is used in a range-request optimized font, its one meta-block should have the ISUNCOMPRESSED bit set to 1.

Static file compression compatibility with range-request method

4.4. Table Ordering

No two tables in a range-request optimized font should share a tag name.

A range-request optimized font should have only one of these tables:

The term outline table is used to describe the one table which is either a CFF table, CFF2 table, or glyf table.

The outline table data in a range-request optimized font should lie at the end of the file.

If a CFF table exists, the CharString data should lie at the end of the CFF table.

If a CFF2 table exists, the CharString data should lie at the end of the CFF2 table.

Font Collections support

4.5. Glyph Independence

Note: The goal of this section is to make every glyph independent from each other.

A range-request optimized font should not use Compound glyphs.

Supporting fonts with composite glyphs via range-request

Note: Compound glyphs can be flattened by inlining their component glyphs to become additional contours.

A range-request optimized font should not use Subroutines.

Note: CFF glyph CharStrings can be flattened by inlining subroutines to become additional CharString bytes.

4.6. Glyph Order

Glyphs inside a range-request optimized font should be sorted in the file to keep glyphs often used in the same documents close together in the file.

Note: Putting the most frequently used glyphs together in the font increases the likelihood that the browser can download a contiguous sequence of necessary glyphs in a single range-request, thereby minimizing overhead.

Note: Reordering glyphs in a font is the same conceptual operation as renaming glyphs to have different glyph IDs. Therefore, this operation cannot be completed if glyph IDs must be preserved. Because glyph IDs are internal to text processing procedures and are not persisted, this requirement is not expected to be particularly burdensome.

One suggested method of sorting the glyphs in the file is by usage document frequency inside a relevant corpus.

A corpus is defined to be a collection of documents, where a documents includes a collection of glyphs necessary to render some textual content.

Note: For a particular website, a corpus might be defined to be individual page loads of pages on that website.

The usage document frequency of a particular glyph inside a corpus is defined by the number of documents in the corpus which use that glyph, divided by the number of documents in the corpus.

Note: This is distinct, but similar, to the number of times the glyph is used throughout the entire corpus.

The usage document frequency of the glyphs in a range-request optimized font should be decreasing throughout the font; that is, the most frequently used glyphs should have the lowest glyph IDs.

Note: Glyph ID 0 cannot be renamed in OpenType, TrueType, WOFF, and WOFF 2 fonts. All other glyphs can be renamed.

Note: Because the goal is simply to minimize overhead by placing similarly-used glyphs together, it may actually be possible to do better than ordering by simple frequency for a particular corpus. For example, some corpuses may have cliques of glyphs which have different frequencies but which nevertheless always seem to be used together.

A suggested ordering is included in Appendix A below.

5. Browser Behaviors

5.1. First Request

When a browser encounters the CSS opt-in mechanism, it is instructed to use IFT to load the fonts. First, it follows the steps in the IFT method selection section above. If those steps result in using the range-request method, the rest of this section applies.

The IFT method selection involves a single round-trip to the server, and if the range-request method is being used, the server’s response starts sending the font file to the browser. The browser should start parsing the partial font data as it is being loaded from the server. The browser should not wait until the entire file has been received before parsing its contents.

There is a certain amount of data from the beginning of the font file which the browser should unconditionally download. The boundary at the end of this data is called the range-request threshold.

Note: The first request does not have to be a range request. If the browser expects the range-request threshold to lie within the first n bytes of the font, the first request may be a range request for the first n bytes of the font. However, a browser may instead make a non-range request, parse the data as it is being streamed from the server, and discover that it has reached the range-request threshold while data is still being streamed.

Once all the data before the range-request threshold has been loaded by the browser, the browser may either close this connection to the server, or it may choose to leave the connection open and let the font data continue loading in the background.

A browser may choose to add a [RFC7233] Range header to the initial request during the IFT method selection if it has reason to believe the range it requests will be large enough and it prefers to not close this connection to the server.

Note: Different browsers may choose different range-request thresholds. Some browsers may treat this threshold as occuring at the end of the sfnt tableDirectory. Other browsers may treat this threshold as occurring just before any outline data, provided the outline data appears at the end of the font. Other browsers may place this threshold at the very beginning of the file, thereby treating the whole file as able to be downloaded with range-requests.

5.2. Subsequent Requests

After all the data before the range-request threshold has been loaded by the browser, the browser will determine which additional byte ranges in the file are necessary to load. It will then issue [RFC7233] HTTP Range Requests for at least those ranges.

Note: Browsers are encouraged to coalesce range requests for nearby areas of the file, to minimize the amount of range-request overhead required. Browsers are encouraged to inform these coalescing decisions from network configuration parameters and bandwidth / latency observations.

Note: If the font file has followed all of the organization guidelines above, all information required for laying out content and performing shaping will lie before any of the outline data in the file, and every glyph’s outline will be independent from every other glyph. Therefore, the browser can treat the range-request threshold as being just before outline data begins, and once it has loaded up to that threshold, it can lay out page content. After laying out the page, downloading all the necessary outlines can be done with a collection of independent and parallel range requests. This works particularly well for Chinese, Japanese, and Korean fonts, where 90% or more of the font data is outline data.

Note: Another valid alternative is to treat the entire font as residing on an asynchronous virtual filesystem, and have the browser track which ranges of the font it ended up reading during its normal operation. The browser could then request those regions in range requests.

6. Server Behaviors

Servers supporting the range-request IFT method must support [RFC7233] range requests.

Servers supporting the range-request IFT method should support compression via the [RFC7231] Content-Encoding header or the [RFC7230] Transfer-Encoding header, rather than having the font file itself be statically compressed.

7. Security Considerations

8. Privacy Considerations

See Privacy Considerations

Method-specific privacy sections

Appendix A: Suggested glyph/character ordering

Note: This section describes ordering of characters, not glyph IDs, because the meaning of glyph IDs are not consistent across different fonts. To optimize a particular font according to the ordering listed here, the characters will have to be mapped to glyph IDs inside the font. This approach of mapping characters to glyphs for ordering purposes works particularly well for ideographic languages with large character sets.

Populate suggested character ordering for range-request method

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Conformance Classes

A conformant user agent must implement all the requirements listed in this specification that are applicable to user agents.

A conformant server must implement all the requirements listed in this specification that are applicable to servers.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-FONTS-5]
Myles Maxfield; Chris Lilley. CSS Fonts Module Level 5. 21 December 2021. WD. URL: https://www.w3.org/TR/css-fonts-5/
[OPENTYPE]
OpenType specification. URL: http://www.microsoft.com/typography/otspec/default.htm
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[RFC7230]
R. Fielding, Ed.; J. Reschke, Ed.. Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing. June 2014. Proposed Standard. URL: https://httpwg.org/specs/rfc7230.html
[RFC7231]
R. Fielding, Ed.; J. Reschke, Ed.. Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content. June 2014. Proposed Standard. URL: https://httpwg.org/specs/rfc7231.html
[RFC7233]
R. Fielding, Ed.; Y. Lafon, Ed.; J. Reschke, Ed.. Hypertext Transfer Protocol (HTTP/1.1): Range Requests. June 2014. Proposed Standard. URL: https://httpwg.org/specs/rfc7233.html
[RFC7932]
J. Alakuijala; Z. Szabadka. Brotli Compressed Data Format. July 2016. Informational. URL: https://www.rfc-editor.org/rfc/rfc7932
[TRUETYPE]
TrueType™ Reference Manual. URL: https://developer.apple.com/fonts/TrueType-Reference-Manual/
[WOFF]
Jonathan Kew; Tal Leming; Erik van Blokland. WOFF File Format 1.0. 13 December 2012. REC. URL: https://www.w3.org/TR/WOFF/
[WOFF2]
Vladimir Levantovsky; Raph Levien. WOFF File Format 2.0. 6 July 2021. REC. URL: https://www.w3.org/TR/WOFF2/

Issues Index

Server-recommended IFT Method selection
Using WOFF2 files with range-request mechanism doesn’t seem to be a viable option
Static file compression compatibility with range-request method
Font Collections support
Supporting fonts with composite glyphs via range-request
Method-specific privacy sections
Populate suggested character ordering for range-request method