I have a Content Editor Web Part in SharePoint 2007 that includes a function to insert several tags on the page with different JavaScript sources.
For some reason, it takes about 4-5 minutes and several refreshes in order to get one of my JavaScript sources (an API) to load. Typically, this will only happen in the morning, upon my first visit to my SharePoint site.
This problem used to happen more frequently, but I have since placed a series of buttons that trigger reloads of the function that includes script source code on the page (see code-block below: Credit to Herve Tourpe)
Could someone give me insight as to why this is happening?
For more information, I am using the MIT Simile Timeline API. Usually, once I log on to the site in the morning the error on the page is that "Timeline" is undefined (which is, clearly, the most integral class from the API file).
To me, this either means that the function that executes the timeline hasn't waited long enough for the API to load, or there is some sort of a problem with the following function:
function includeJSScript(p_file) {
// before we insert this script, we need to check if it already exists
var bAlreadyExists = false;
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].src == p_file) {
bAlreadyExists = true;
break;
}
}
if (!bAlreadyExists) {
var v_script = document.createElement('script');
v_script.type = 'text/javascript';
v_script.src = p_file;
document.getElementsByTagName('head')[0].appendChild(v_script);
}
}