SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Code:
    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:

    Code:
    <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

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dantheman50_98 View Post
    Can I put these both in their own external js file?
    Remove the HTML script tags from the file, and yes you can.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2008
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah great, that's worked a treat. Thanks!

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    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.
    The only code I hate more than my own is everyone else's.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2012
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •