Usually I would use $(document).ready(...) construct to do this, but since even jQuery itself is loaded at page bottom this becomes impossible.
For example we can use existing tags to arrange this or create new tag just for that. Here is how I see it.
queue_namein example above is optional and allows to have several queues on one page.
minify_astells how queued data should be minified. When omitted no minification happens.
- Tag <script> is added inside just to keep IDE auto-complete working, otherwise whole JS code would be highlighted as big HTML error.
- All <script ...> and </script> tags would be stripped from the result to create one unified block.
- Each m_Queue pair tag can be interpreted as sort-of <inp2:m_Capture to_var=""> ... </inp2:m_Capture> that appends new data to already queued data.
- Each m_Queue non-pair tag can be interpreted as <inp2:m_Param.../> tag to get data from that parameter.
Hope you can see potential of m_Queue tag, since it allows to put absolutely anything into queue for later usage while keeping related data in same place in template.