Can I use a script to check if a JS file is loaded?
No. The page isn't seen until the PHP script has flushed all its output, by which time it's too late to do anything. But most browsers are smart enough to only load an external resource once per page anyway.
You should have an asset management system in your PHP to see whats being included into the page.
Ultra simple example (derived from link):
<html> <head><?php Page::render_head(); ?></head> <body> <div id="header"></div> <div id="content"><?php Page::render_content(); ?></div> <div id="footer"></div> </body> </html>
<?php Page::add_head('<title>Hello World!</title>'); ?> <h1>Hello</h1> <p>World</p>
©2020 All rights reserved.