Externally referenced documents

In this section, the term "primary document" refers to a rootmost SVG document or SVG document fragment. If an SVG document is loaded directly by a web browser (e.g., the browser views file foo.svg), then it is the primary document. If an SVG document as a whole is referenced for inclusion by a parent document, such as using the HTML 'object' or SVG 'animation' elements, then that document itself shall also be a primary document. If an SVG document fragment is embedded inline within a non-SVG document, then the 'svg' element shall define the root element for a subtree which acts as a primary document. In other words, it is the rootmost 'svg' element for an SVG document fragment.

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. In particular, 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. For example, if document A.svg includes an 'animation' element which refers to B.svg, then both are primary documents, and both shall represent separate, self-contained documents with their own scripting contexts and animation timelines.

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.

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 conceptual model is that each resource document is loaded only once; 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.

The conceptual processing model for resource documents is that the document is processed as a complete and separate SVG document instance. 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; stylesheets are applied and the CSS cascade is run; timelines are initiated and animations begin; sXBL transformations are applied (not relevant to SVGT1.2); etc.

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].


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.


Loading of external references

There are two contexts in which externally referenced documents are processed in SVG, depending on how the SVG document itself is used. An SVG document can be a "primary document" or a "resource document", and this distinction provides the processing context.

Primary documents

The term "primary document" refers to a rootmost SVG document or an SVG document fragment that is loaded in whole directly into the user agent. Examples of a primary document include:

Resource documents

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.

Resource processing

The conceptual processing model for both primary and resource documents is that each document is processed as a complete and separate SVG document instance: 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; stylesheets are applied and the CSS cascade is run; timelines are initiated and animations begin; etc. Implementations are free to optimize for the case of a large resource library loaded into multiple primary documents, but logically each (primary?) document shall represent its own separate, self-contained document instance.

For example, if document A.svg includes an 'animation' element which refers to B.svg, then both are primary documents, and both shall represent separate, self-contained documents with their own scripting contexts and animation timelines.

The conceptual model is that each resource document is loaded only once; 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.

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].

As with a primary document, multiple references to the same external media file lead to separate media timeline. As with a resource document, the same external script file is processed only once in the case of multiple references in the same scripting context.