I have changed my coding style with more complex projects to loading pages (And their embedded scripts) "on demand" recently. However, it is difficult to debug those scripts as when they are loaded like:
jQuery.get('/myModularPage', function(html){ /* insert the loaded page into the DOM */ });
or
$('#some-container').load('/myOtherPage');
These scripts run perfectly, but if I'm debugging, how can I set breakpoints in these dynamically loaded pages and scripts?
Add this to your js files where you want it to break:
debugger;
Then step into/over/out like any other debugger.
Works for dynamically loaded scripts and pages. Only works in Chrome as far as I know.