I have built several projects now using AJAX to load page fragments instead of whole pages, and am pretty pleased with how this all works. I have come to the point where I wanted to avoid having to load all the JavaScript files for all possible parts of the application upon a first visit by a new user, so I came up with a scheme for loading functions only when they relate to a particular page fragment.
Essentially, I enclose the code to be downloaded in XML tags (a CDATA block), check whether the stuff has been loaded before, and if not, eval() the string of code. This works, with one caveat: instead of writing "function foo()", I have to write "foo = function ()", so that the function definition persists beyond the lifetime of the routine that accepts the download.
All this is fine, but I have not found a way to make code downloaded in this way visible to the Firebug run-time environment. This makes debugging pretty tough.
Any suggestions as to what I need to do to achieve the holy grail: code downloaded with the HTML that uses it, rather than needing to be loaded at the beginning of the application?
Essentially, I enclose the code to be downloaded in XML tags (a CDATA block), check whether the stuff has been loaded before, and if not, eval() the string of code. This works, with one caveat: instead of writing "function foo()", I have to write "foo = function ()", so that the function definition persists beyond the lifetime of the routine that accepts the download.
All this is fine, but I have not found a way to make code downloaded in this way visible to the Firebug run-time environment. This makes debugging pretty tough.
Any suggestions as to what I need to do to achieve the holy grail: code downloaded with the HTML that uses it, rather than needing to be loaded at the beginning of the application?