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?

5
  • Where are you doing the $('head').append() ? Commented Jan 21, 2011 at 18:30
  • 1
    Check this out: github.com/jAndreas/Supply Commented Jan 21, 2011 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) Commented Jan 21, 2011 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 Commented Jan 21, 2011 at 18:48
  • Duplicate of stackoverflow.com/questions/2571164/… Commented Oct 28, 2011 at 19:10

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.