You could issue a GET using XMLHttpRequest, resulting in it getting cached in the browser, then use JavaScript to add the tag to the document, making it load near instantly.
var req = new XMLHttpRequest();
req.onprogress=myUpdateProgressFunction; // whatever you want to do!
req.open('GET', '/js/hugelib.js', true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4)
{
var hugeScript = document.createElement('script');
hugeScript.setAttribute('src','/js/hugelib.js');
document.head.appendChild(hugeScript);
}
};
req.send();
You could also consider just setting the hugeScript.text with the results of the AJAX GET, but I'm fairly sure that would perform poorly.
As a further refinement, you could issue a HEAD request first to see if the item is already cached, if it is, don't attempt the AJAX GET. Again, you'd have to profile performance to see if that actually improves performance or not overall.
NB: I haven't tested the behaviour of this pattern, I'm taking it in good faith that the browser cache will act in a gentlemanly fashion.