The Joomla API (such as $doc->addScript) uses an array to store the JS files paths. They get rendered in the document in the same order they were inserted into the array (FIFO stack). Once a file path is included in the array, if another API tries to insert the same file, the insertion is ignored. This prevents duplicates, but it also means that the files will be rendered according to when they were first included in the FIFO stack. If the same files are attempted to be inserted again, the order of the files will not be altered.
2: What is the insertion order for each of the Joomla parts?i.e. plugins, modules, articles, etc.
I’ll include what I’ve already found out below.
extension files and template override files are processed first and the index.php file of your current template is processed last.