The MRAID Best Practices recommends defining mraid.js as soon as possible - maybe put it in the head:
<html> <head> <script src="mraid.js"></script>
Also take note of this documentation:
Start with the MRAID.addEventListener for ready as shown below. Put
the rest of the MRAID code in displayAd or similar initialization
function. The state must be “ready” before any MRAID APIs can be used.
Failure to observe this requirement risks unpredictable failures for
the ad when it tries to use MRAID functionalities that are not yet
available to it. Occasionally the ready event is fired before the
creative has an opportunity to register a listener. Therefore using
logic like this example represents a best practice.
function init() {
var success = false;
if (document.readyState === 'complete') {
if (typeof mraid !== 'undefined') {
if (mraid.getState() === 'loading') {
mraid.addEventListener('ready', displayAd);
} else if (mraid.getState() === 'default') {
displayAd();
}
success = true;
}
}
return success;
}