require_js currently works in two situations:
1) If you call it before print_header
2) If you call it after print_header
It does not cope with the third situation, which is if you have some code that runs as a consequence of the header code itself. (E.g. your header has some fancy JS in it.) When this happens, it tends to print the script at the beginning of the html file, which makes a mess of the page in IE6 because it breaks doctype detection.
My proposal (and patch) is as follows:
1) Rewrite require_js to support three defined states: before header, after header, and inside header.
2) Add a line of code to weblib print_header so that it dumps the 'inside header' stuff out after the end of the header.
3) Add debugging to check that the two 'special-case' variants of require_js (used when printing the header etc) are not called more than once or in the wrong order.
4) Refactor require_js a bit and improve comments.