2

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 cleared 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?

Bill Dami
  • 3,205
  • 5
  • 51
  • 70
  • Where are you doing the $('head').append() ? – ajma Jan 21 '11 at 18:30
  • 1
    Check this out: https://github.com/jAndreas/Supply – jAndy Jan 21 '11 at 18:38
  • In the callback of the first ajax request the returns all the required resources for the page, immediately after I attach the 'load' listener on $(window) – Bill Dami Jan 21 '11 at 18:44
  • does that SupplyJS lib have any option to set a callback thats fired when the combined resources are done loading into the page? I didn't see anything about that in the readme – Bill Dami Jan 21 '11 at 18:48
  • Duplicate of http://stackoverflow.com/questions/2571164/jquery-event-that-triggers-after-css-is-loaded – BMiner Oct 28 '11 at 19:10

1 Answers1

0

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.

JAAulde
  • 19,250
  • 5
  • 52
  • 63
  • I managed to implement a solution for this but LABjs does look pretty nice and does exactly what I was trying to achieve, I will definitely be saving that for future projects. – Bill Dami Feb 22 '11 at 16:30