jQuery $(window).load() event and dynamically adding external CSS/JS files
I'm working on an AJAX based application that is dynamically loading in resources (external CSS/JS files) based on the page/area that is being loaded into the interface. This works fine however I want to make sure that the external files (which are loaded in simply by doing a $('head').append() of the necessary link and script tags) are finished loading BEFORE the actual page that requires them is accessed.
I thought that I would be able to bind a $(window).load() event which would fire after the external files are finished loading, and the callback would initiate the request for the actual page content. However, it looks from initial tests that the event is not being fired. I also made sure its not due to the file being loaded from my cache as I clear开发者_如何转开发ed my browser cache prior to the test.
Can anyone see any reason why this would happen? Or am i going about this in completely the wrong way?
I believe you should look into code which is actually meant to be used for loading code and managing dependencies. LABjs is very very good at this. Many major jQuery devs and users use LABjs along side jQuery.
精彩评论