Javascript/Jquery combining question

Hi There,

I’m trying to reduce the load speed of an ekmpowershop-powered site, and to do this I’d like to combine all of the javascript scripts into one. As I have no idea how to do this, I’m going to try using the jmerge tool. First I need to put all of the javascript into their own files, rather than directly in the <head> of the site. Which brings me to my point…In the following code, why is the


var $j = jQuery;

wrapped in its own script tags, and is it directly related to the script beneath it?
Can I put these both in their own external js file?

Here is the code in full:


<script type="text/javascript">
var $j = jQuery;
</script>
<script language="JavaScript" type="text/JavaScript">
x = 20;
y = 70;
function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}
function placeIt(obj)
{
	obj = document.getElementById(obj);
	if (document.documentElement)
	{
		theLeft = document.documentElement.scrollLeft;
		theTop = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
		theLeft = document.body.scrollLeft;
		theTop = document.body.scrollTop;
	}
	theLeft += x;
	theTop += y;
	obj.style.left = theLeft + 'px' ;
	obj.style.top = theTop + 'px' ;
	setTimeout("placeIt('layer1')",500);
};
</script>

Thanks,
Dan

Remove the HTML script tags from the file, and yes you can.

Ah great, that’s worked a treat. Thanks!

Most open source projects have a file with the full source uncompressed and compressed. In the simplest of scenarios the compressed version of each library can be copy and pasted into a single file. The only place it gets tricky is with CSS. In most cases all the image references need to be modified. That is probably the least sophisticated way of merging everything but anything else really requires serving the CSS and JS up via server side script which is complicated.

you mean

<script type=“text/javascript”>
var $j = jQuery;
</script>
<script language=“JavaScript” type=“text/JavaScript”> <<<<<< Remove this???
x = 20;
y = 70;
function setVisible(obj)
{
obj = document.getElementById(obj);
obj.style.visibility = (obj.style.visibility == ‘visible’) ? ‘hidden’ : ‘visible’;
}
function placeIt(obj)
{
obj = document.getElementById(obj);
if (document.documentElement)
{
theLeft = document.documentElement.scrollLeft;
theTop = document.documentElement.scrollTop;
}
else if (document.body)
{
theLeft = document.body.scrollLeft;
theTop = document.body.scrollTop;
}
theLeft += x;
theTop += y;
obj.style.left = theLeft + ‘px’ ;
obj.style.top = theTop + ‘px’ ;
setTimeout(“placeIt(‘layer1’)”,500);
};
</script>