This question reminds me of something completely awesome I never knew until I got into Google Pagespeed testing, specifically how Steve Souders attacks the loading asynchronous javascript problem.
Specifically, the <SCRIPT>
tag works much like the <LINK>
tag. It is loading a resource. So in a way, calling an external .js file through <script src=...>
is practically the same thing in a way.
The method is called menu-degrading scripts. In other words, once the resource is loaded, the inline portion of the tag gets executed. It requires a snippit of code to be placed in the source file, but it causes the inline source to be executed after it is loaded. (through some event handlers and eval( curScript.innerHTML );
)
So if you have an external .js file to load, but want it to do something after it is loaded, you can do this:
<script src="menu-degrading.js" type="text/javascript">
// something in javascript you want to do...
</script>
The gem about this, to me, is the fact that almost every external resource or <LINK>
ultimately can work like this if done properly. When I first ran across this, I would have never thought to try both externally loading and in-lining a resource.
<link rel="stylesheet" type="text/css" href={somefile.css} >
/* default inline resource if not found */
.body { background:#000000;color:FFFFFF; }
/* etc... minimal defaults */
</link>
I haven't tried this yet, but inline code might work with 404 errors to create default resources when not found. If you have time to test this, let me know!