Cache dataLoadedPromise and move the code out of viewer.js