Talk:Useful include function

Im sorry if i have miss spelled any thing, im amazed if i havent. Maybe it should say import instead of include and it should definitely support shaders.

dose any body have a good idea for a good way for that?

I'm thinking add tag and fetch source code later and setting the id of the script tag to the name of the file(without the ending).

--Neppord 04:44, 13 November 2009 (UTC)

The problem with this is that the scripts are fetched asynchronously, so you can't depend on the include'ed libraries because you don't know when they have finished loading.

A more complete solution would be to require a parameter passed to the include method called "watch". The include method would poll for a variable in the global scope to determine if the library has finished loading yet. The third parameter would then be a callback function that gets executed once the "watch" variable is detected.

Something like:

Here is a test that shows where the original include function fails, and where my version works as intended:

Also note that my method doesn't touch the DOM to check for previously loaded libraries, which prevents unnecessary reflows.

--Developit 17:46, 7 July 2010 (UTC)