protected function CompactJs( $sText )
	{
	    $sBuffer = "";
	    $i = 0;
	    $iStop = strlen($sText);
	
	    // Compact and Copy PHP Source Code.
	    $sChar = '';
	    $sLast = '';
	    $sWanted = '';
	    $fEscape = false;
	    for( $i = $i; $i < $iStop; $i++ )
	    {
	        $sLast = $sChar;
	        $sChar = substr( $sText, $i, 1 );
	
	        // \ in a string marks possible an escape sequence
	        if ( $sChar == '\\' )
	            // are we in a string?
	            if ( $sWanted == '"' || $sWanted == "'" )
	                // if we are not in an escape sequence, turn it on
	                // if we are in an escape sequence, turn it off
	                $fEscape = !$fEscape;
	
	        // " marks start or end of a string
	        if ( $sChar == '"' && !$fEscape )
	            if ( $sWanted == '' )
	                $sWanted = '"';
	            else
	                if ( $sWanted == '"' )
	                    $sWanted = '';
	
	        // ' marks start or end of a string
	        if ( $sChar == "'" && !$fEscape )
	            if ( $sWanted == '' )
	                $sWanted = "'";
	            else
	                if ( $sWanted == "'" )
	                    $sWanted = '';
	
	        // // marks start of a comment
	        if ( $sChar == '/' && $sWanted == '' )
	            if ( substr( $sText, $i + 1, 1 ) == '/' )
	            {
	                $sWanted = "\n";
	                $i++;
	                continue;
	            }
	
	        // \n marks possible end of comment
	        if ( $sChar == "\n" && $sWanted == "\n" )
	        {
	            $sWanted = '';
	            continue;
	        }
	
	        // /* marks start of a comment
	        if ( $sChar == '/' && $sWanted == '' )
	            if ( substr( $sText, $i + 1, 1 ) == '*' )
	            {
	                $sWanted = "*/";
	                $i++;
	                continue;
	            }
	
	        // */ marks possible end of comment
	        if ( $sChar == '*' && $sWanted == '*/' )
	            if ( substr( $sText, $i + 1, 1 ) == '/' )
	            {
	                $sWanted = '';
	                $i++;
	                continue;
	            }
	
	        // if we have a tab or a crlf replace it with a blank and continue if we had one recently
	        if ( ( $sChar == "\t" || $sChar == "\n" || $sChar == "\r" ) && $sWanted == '' )
	        {
	            $sChar = ' ';
	            if ( $sLast == ' ' )
	                continue;
	        }
	
	        // skip blanks only if previous char was a blank or nothing
	        if ( $sChar == ' ' && ( $sLast == ' ' || $sLast == '' ) && $sWanted == '' )
	            continue;
	
	        // add char to buffer if we are not inside a comment
	        if ( $sWanted == '' || $sWanted == '"' || $sWanted == "'" )
	            $sBuffer .= $sChar;
	
	        // if we had an escape sequence and the actual char isn't the escape char, cancel escape sequence...
	        // since we are only interested in escape sequences of \' and \".
	        if ( $fEscape && $sChar != '\\' )
	            $fEscape = false;
	    }
	
	    // Copy Rest
	    $sBuffer .= substr( $sText, $iStop );
	
	    return( $sBuffer );
	}
protected function CompactJs( $sText )
	{
	    $sBuffer = "";
	    $i = 0;
	    $iStop = strlen($sText);
	
	    // Compact and Copy PHP Source Code.
	    $sChar = '';
	    $sLast = '';
	    $sWanted = '';
	    $fEscape = false;
	    for( $i = $i; $i < $iStop; $i++ )
	    {
	        $sLast = $sChar;
	        $sChar = substr( $sText, $i, 1 );
	
	        // \ in a string marks possible an escape sequence
	        if ( $sChar == '\\' )
	            // are we in a string?
	            if ( $sWanted == '"' || $sWanted == "'" )
	                // if we are not in an escape sequence, turn it on
	                // if we are in an escape sequence, turn it off
	                $fEscape = !$fEscape;
	
	        // " marks start or end of a string
	        if ( $sChar == '"' && !$fEscape )
	            if ( $sWanted == '' )
	                $sWanted = '"';
	            else
	                if ( $sWanted == '"' )
	                    $sWanted = '';
	
	        // ' marks start or end of a string
	        if ( $sChar == "'" && !$fEscape )
	            if ( $sWanted == '' )
	                $sWanted = "'";
	            else
	                if ( $sWanted == "'" )
	                    $sWanted = '';
	
	        // // marks start of a comment
	        if ( $sChar == '/' && $sWanted == '' )
	            if ( substr( $sText, $i + 1, 1 ) == '/' )
	            {
	                $sWanted = "\n";
	                $i++;
	                continue;
	            }
	
	        // \n marks possible end of comment
	        if ( $sChar == "\n" && $sWanted == "\n" )
	        {
	            $sWanted = '';
	            continue;
	        }
	
	        // /* marks start of a comment
	        if ( $sChar == '/' && $sWanted == '' )
	            if ( substr( $sText, $i + 1, 1 ) == '*' )
	            {
	                $sWanted = "*/";
	                $i++;
	                continue;
	            }
	
	        // */ marks possible end of comment
	        if ( $sChar == '*' && $sWanted == '*/' )
	            if ( substr( $sText, $i + 1, 1 ) == '/' )
	            {
	                $sWanted = '';
	                $i++;
	                continue;
	            }
	
	        // if we have a tab or a crlf replace it with a blank and continue if we had one recently
	        if ( ( $sChar == "\t" || $sChar == "\n" || $sChar == "\r" ) && $sWanted == '' )
	        {
	            $sChar = ' ';
	            if ( $sLast == ' ' )
	                continue;
	        }
	
	        // skip blanks only if previous char was a blank or nothing
	        if ( $sChar == ' ' && ( $sLast == ' ' || $sLast == '' ) && $sWanted == '' )
	            continue;
	
	        // add char to buffer if we are not inside a comment
	        if ( $sWanted == '' || $sWanted == '"' || $sWanted == "'" )
	            $sBuffer .= $sChar;
	
	        // if we had an escape sequence and the actual char isn't the escape char, cancel escape sequence...
	        // since we are only interested in escape sequences of \' and \".
	        if ( $fEscape && $sChar != '\\' )
	            $fEscape = false;
	    }
	
	    // Copy Rest
	    $sBuffer .= substr( $sText, $iStop );
	
	    return( $sBuffer );
	}
protected function CompactJs ( $ sText ) { $ sBuffer = "" ; $ i = 0 ; $ iStop = strlen ( $ sText ) ; // Compact and Copy PHP Source Code. $ sChar = '' ; $ sLast = '' ; $ sWanted = '' ; $ fEscape = false ; for ( $ i = $ i ; $ i < $ iStop ; $ i ++ ) { $ sLast = $ sChar ; $ sChar = substr ( $ sText , $ i , 1 ) ; // \ in a string marks possible an escape sequence if ( $ sChar == '\\' ) // are we in a string? if ( $ sWanted == '"' || $ sWanted == "'" ) // if we are not in an escape sequence, turn it on // if we are in an escape sequence, turn it off $ fEscape = ! $ fEscape ; // " marks start or end of a string if ( $ sChar == '"' && ! $ fEscape ) if ( $ sWanted == '' ) $ sWanted = '"' ; else if ( $ sWanted == '"' ) $ sWanted = '' ; // ' marks start or end of a string if ( $ sChar == "'" && ! $ fEscape ) if ( $ sWanted == '' ) $ sWanted = "'" ; else if ( $ sWanted == "'" ) $ sWanted = '' ; // // marks start of a comment if ( $ sChar == '/' && $ sWanted == '' ) if ( substr ( $ sText , $ i + 1 , 1 ) == '/' ) { $ sWanted = "\n" ; $ i ++ ; continue ; } // \n marks possible end of comment if ( $ sChar == "\n" && $ sWanted == "\n" ) { $ sWanted = '' ; continue ; } // /* marks start of a comment if ( $ sChar == '/' && $ sWanted == '' ) if ( substr ( $ sText , $ i + 1 , 1 ) == '*' ) { $ sWanted = "*/" ; $ i ++ ; continue ; } // */ marks possible end of comment if ( $ sChar == '*' && $ sWanted == '*/' ) if ( substr ( $ sText , $ i + 1 , 1 ) == '/' ) { $ sWanted = '' ; $ i ++ ; continue ; } // if we have a tab or a crlf replace it with a blank and continue if we had one recently if ( ( $ sChar == "\t" || $ sChar == "\n" || $ sChar == "\r" ) && $ sWanted == '' ) { $ sChar = ' ' ; if ( $ sLast == ' ' ) continue ; } // skip blanks only if previous char was a blank or nothing if ( $ sChar == ' ' && ( $ sLast == ' ' || $ sLast == '' ) && $ sWanted == '' ) continue ; // add char to buffer if we are not inside a comment if ( $ sWanted == '' || $ sWanted == '"' || $ sWanted == "'" ) $ sBuffer .= $ sChar ; // if we had an escape sequence and the actual char isn't the escape char, cancel escape sequence... // since we are only interested in escape sequences of \' and \". if ( $ fEscape && $ sChar != '\\' ) $ fEscape = false ; } // Copy Rest $ sBuffer .= substr ( $ sText , $ iStop ) ; return ( $ sBuffer ) ; }
A 3rd party implementation for compact a javascript.

@Author: Hannes Dorn
@Company: IBIT.at
@Homepage: http://www.ibit.at
@Email: hannes.dorn@ibit.at
@Comment: Original compact PHP code. Changes by João Gilberto Magalhães (ByJG) to Work on JavaScript.
@param string $sText
@return unknown
A 3rd party implementation for compact a javascript .