Peter Michaux wrote: > On 12/13/06, Fred <[EMAIL PROTECTED]> wrote: > > > > getElementsByTagName only fails in the above scenario if a second load > > script is used with a different path to the first one (hence you need > > an updated path) *and* it is in the head element. Below is a load > > script that works fine as long as the second and subsequent loads are > > done from the body. It can easily be extended to include more > > features, I just wanted to show you can avoid a recursive node walk > > (which must grate on anyone looking for a clean design). > > The recursive descent is only document->head->head elements. It is not > a complex deep walk with long descents into fruitless branches. It is > almost a direct hit especially if you put the loader script inclusion > high in the head element.
My error, I assumed you'd used the same approach as that implemented in the other thread which includes processing instructions for recursion (although it should have occurred to me that since no element in the head that can have childNodes it would never be called). The only remaining issue is that you need to run down all the (progressively more numerous) elements each time the load function is called, which is probably not a concern as it should only be called a couple of times at most. Have you tested recursive loading? That is, calling a load script from a load script? Don't roll your eyes like that, someone will try it! ;-D I can also imagine someone trying to put functions into separate files, then using a load script as a kind of include file. They could end up trying to load a very large number of files using a large number of nested load scripts. Devil's advocate is a fun job. > There are situations where you can't move scripts from the head to > body elements just willy-nilly I can only think of cases where you might want elements to be parsed after a particular script element, but those elements can only appear in the head. I imagine those cases are few and far between. > > <http://www.w3schools.com/js/js_whereto.asp> Ugggh... my opinion of w3schools just slipped a couple more notches: "JavaScripts in the body section will be executed WHILE the page loads. JavaScripts in the head section will be executed when CALLED." Whoever wrote that needs to learn about execution contexts, specifically global code and function code - Section 10.1.2 of the ECMAScript specification refers. Javascript will be executed according to the rules for parsing and executing contained in the ECMAScript Language Specification, which is essentially that global code is executed as it is encountered, functions will be executed when called. The very act of declaring a function executes global code, wherever it is. There are no processing or execution rules based on where in an HTML document the script element (and hence the code) is physically located. The only side effects of that might be if a script element is not in the head or body a browser might decide to ignore it or put it into the head or body. As far as I know, no browser will do the first, they all do the second, even if the script element is placed before the DOCTYPE or after the closing body tag (or between head and body tags, or anywhere it shouldn't be). -- Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
