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

It does not need to be in it's own <script> tag, it's not related to the code beneath it, and they can both be put in an external .js

... 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?

Yes but they don't logically belong together. The statement $j = jQuery; belongs with whatever statements use $j.

It is more common to see $j = jQuery.noConflict(); .

.noConflict does the same as $j = jQuery; but also frees up $ so jQuery can coexist with other libs that use $, eg Prototype.

Airshow

Thanks guys, that has sorted it out nicely!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.