Re: externalResourcesRequired and SVGLoad

On Thursday, October 23, 2003, at 09:50  AM, Denis Bohm wrote:
> I would like to create an element with a reference to an external  
> resource after the document has been loaded from JavaScript (possibly  
> on a user initiated event).  [...] So I would like an event that is  
> triggered when the external resource has been loaded [...] Will the  
> wording cover this situation?

It was your desire that sparked me looking at this. I hadn't realized  
that you were dynamically creating the element, though IMO what you  
desire should be made possible by the UA. Code like the following  
should (IMHO) fire the Loaded() function only after that element has  
been loaded from the url:

function ThisIsCalledAfterTheDocumentIsLoaded(){
	var foo = svgDoc.createElement('use');
	foo.addEventListener('load',Loaded,false);
	foo.setAttribute('externalResourcesRequired','true');
	foo.setAttributeNS('http://www.w3.org/1999/ 
xlink','xlink:href','bar.svg#foo');
	svgDoc.documentElement.appendChild(foo);
}



However, I can see how this could get 'tricky' if the UA loaded the url  
asynchronously, as soon as it was set. Should the below code fire the  
load event, when the SVGLoad handler is attached to the object after it  
has fully loaded?

function ThisIsCalledAfterTheDocumentIsLoaded(){
	var foo = svgDoc.createElement('use');
	foo.setAttribute('id','foo');
	foo.setAttribute('externalResourcesRequired','true');
	foo.setAttributeNS('http://www.w3.org/1999/ 
xlink','xlink:href','bar.svg#foo');
	svgDoc.documentElement.appendChild(foo);
}

function ThisIsCalledFiveMinutesLater(){
	svgDoc.getElementById('foo').addEventListener('load',Loaded,false);
}

(IMHO the answer is no, the SVGLoad event should not fire in the above  
case.)




What about this code, if the referenced URL is already cached and  
fetched before the SVGLoad handler is attached?

function ThisIsCalledAfterTheDocumentIsLoaded(){
	var foo = svgDoc.createElement('use');
	svgDoc.documentElement.appendChild(foo);
	foo.setAttributeNS('http://www.w3.org/1999/ 
xlink','xlink:href','bar.svg#foo');
	foo.addEventListener('load',Loaded,false);
	foo.setAttribute('externalResourcesRequired','true');
}

(IMHO the answer is "Dude, you're just asking for trouble.")




Denis, in case the savvy ASV developers have implemented the xlink:href  
fetching asynchronously, have you tried ensuring that your code is as  
the first example, setting the SVGLoad handler before the xlink:href?



The sample wording I previously supplied may or may not be interpreted  
to cover your desired case. Frankly, given the issues I've raised above  
regarding asynchronous fetching, I think:

* a decision needs to be made on how to handle asynchronous fetching of  
external resources created dynamically via code:
	-- externalResourcesRequired="true" -> synchronous ?
	-- externalResourcesRequired="false" -> asynchronous ?
	-- what if the externalResourcesRequired flag is set during an  
asynchronous fetch?

* a decision needs to be made on how to handle an SVGLoad event  
dynamically attached to an object after it has finished loading:
	-- should it fire immediately?
	-- never?
	-- only if any externalResources are changed and loaded?

* the results of these decisions needs to be included explicitly in the  
1.2 specs.


--
Gavin Kistner @ Refinery, Inc.
gavin@refinery.com
work: +1.303.444.1777

Received on Thursday, 23 October 2003 12:33:13 UTC