Import js link from within another js link?

Hello,

I’m trying to combine a few Google Custom Search js snippets and links into one file. Mainly for ease of editing. This is going in .html pages. I know I could use .htaccess to run php on the page in order to use SSI’s but it’s not worth the possible performance hit for this one piece as the rest of the site is plain html. I figured I would just use document.write to insert the script link into the other but this does not work for some reason. Save the document.write lectures please. Should this work? Or maybe something about the google script needs to run on it’s own? Or should this not work and you know how to make it work? Thanks!

Secondly, if you put a document.write statement in a external js script is the document.write stuff cached along with the external js link?

hi,

maybe you are doing it wrong, you can do it like this:

  1. Link one js file
  2. in linked js file put script which will load javascript:

Example


var ar = new Array();
ar.push('www.google.com/custom.js');
ar.push('www.wiseblog.info/tag.js');
for(var i = 0; i < ar.length; i++)
{
 var el = document.createElement('script');
 el.setAttribute('type', 'text/javascript');
 el.setAttribute('src', ar[i]);
 document.getElementsByTagName("head")[0].appendChild(el);
}

I hope that this will help you

Hello, unfortunately I can’t do that because the link does not reside on my server. Normally I would just copy and paste it onto to mine but it’s a large google search script. Who nows how often they update that ya know.