14.1.6 Loading of external references

This section defines two terms: "primary documents" and "resource documents" and the processing of these two types of SVG documents with respect to the loading of externally referenced documents.

The term "primary document" refers to a rootmost SVG document or SVG document fragment in the following three situations:

The term "resource document" refers to a complete, self-contained SVG document which has at least one of its elements referenced as a resource by a primary document. For example, suppose document A.svg is loaded into a browser for viewing, and this document refers to a path element within B.svg via an IRI reference on a 'use' element. In this case, A.svg is a primary document and B.svg is a resource document.

Primary and resource documents share a common conceptual processing model. The conceptual processing model is that events (e.g., the document load event) are fired; scripts are executed in normal fashion and resource documents are modifiable by scripts; coordinate systems transformations are applied; timelines are initiated and animations begin; etc.

Primary and resource documents however differ on the following point. The conceptual model is that a primary document may be loaded multiple times (for example when several 'animation' elements refer to the same document) while each resource document is loaded only once per primary document context. If the same resource document is referenced multiple times directly or indirectly by the same primary document, that resource document is only retrieved and processed one time. Conceptually, each primary document must have an associated dictionary that maps all IRIs for resource documents it references; initially it is populated only with the primary document itself. Each resource or subresource loaded directly or indirectly must be resolved through that dictionary with resource documents downloaded as needed. The IRI used as the key in the dictionary of resource documents must be the absolute IRI after resolving it against any applicable base IRI, and comparisons of the dictionary keys must be performed using a Simple String Comparison, as defined in section 5.3.1 of Internationalized Resource Identifiers [RFC3987].

Similarly to primary documents, multiple references to the same external media lead to separate media timeline.

Similarly to resource documents, in the case of multiple references, in the same scripting context, to the same external script file, the script file is processed once.

Implementations are free to optimize for the case of large resource library loaded into multiple primary documents, but logically each primary document shall represent its own separate, self-contained document instance.