Reputation: 75
I'm trying to split out a "prebid" file , so as I can have seperate files from the "bidders", analytics client, bidder settings and some other bits. I've basically made my original file the main.js and have split out some of the code into different files such as
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
requirejs(['bidder_settings']);
requirejs(['pbjs_config']);
pbjs.requestBids({
bidsBackHandler: initAdserver,
timeout: PREBID_TIMEOUT
});
});
i'm trying to call in the files within the orginal file, so as it pulls those bits in, it sometimes works but other times it doesnt seem to load certain bits, any clue what i'm doing wrong/ is there a way to make sure the file loads the "modules/ seperate file" in sequencence down the page?
Upvotes: 0
Views: 45
Reputation: 69
This sounds like an asynchronous race condition on your page where requirejs is not loading your modules by the time Prebid needs them to finish the auction. According to the [requirejs docs] (https://requirejs.org/docs/api.html#jsfiles) you should be using a callback to then run code that will require your loaded modules.
example:
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
requirejs(['bidder_settings', 'pbjs_config', ],
function (bidder_settings, pbjs_config) {
pbjs.que.push(function () {
pbjs.addAdUnits(adUnits);
requirejs(['bidder_settings']);
requirejs(['pbjs_config']);
// do what you need with modules here
pbjs.requestBids({
bidsBackHandler: initAdserver, // make sure you utilize disableInitialLoad
timeout: PREBID_TIMEOUT
});
});
}
);
Upvotes: 1