4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 JavaScript and GZip compression
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Milchbazi
Junior WebHelper
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA

PostPosted: Tue Mar 11, 2003 11:17 pm (14 years, 9 months ago) Reply with QuoteBack to Top

Hi,

is it possible to run a JavaScript with a GZip copressed PHP site? How?

Thx a lot,
Milchbazi

________________________________
TS Designs
___________________________
OfflineView User's ProfileFind all posts by MilchbaziSend Personal MessageVisit Poster's Website
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Wed Mar 12, 2003 1:03 am (14 years, 9 months ago) Reply with QuoteBack to Top

that shouldn't be a problem at all...what's the problem you're having exactly?

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
drathbun
WebHelper
WebHelper


Joined: 01 Mar 2003
Posts: 69
Location: Texas

PostPosted: Wed Mar 12, 2003 1:58 am (14 years, 9 months ago) Reply with QuoteBack to Top

The question is irrelevant. Confused One is a server process, and the other is a client process.

GZip runs on the server, and compresses the HTML page (which includes the javascript) before sending it to the browser. The browser uncompresses the data stream, and then interprets the page. Remember, javascript is client side scripting, so anything the server does should not affect it at all.

At least that is my understanding of it.

Dave

________________________________
Dave
Photography Site :: Query Tools Forum :: Weekend Fun
OfflineView User's ProfileFind all posts by drathbunSend Personal MessageVisit Poster's Website
Milchbazi
Junior WebHelper
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA

PostPosted: Wed Mar 12, 2003 2:15 am (14 years, 9 months ago) Reply with QuoteBack to Top

But why does it not work? I have different kinds of Java scripts and they work without compression but if I enable GZip compression is it broken.

Par example a auto-select dropdown menu and a bbcode-editor.

Thx
Milchbazi

________________________________
TS Designs
___________________________
OfflineView User's ProfileFind all posts by MilchbaziSend Personal MessageVisit Poster's Website
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Wed Mar 12, 2003 7:02 am (14 years, 9 months ago) Reply with QuoteBack to Top

Are you putting the Javascript in an external file, or is it directly in the HTML? Some browsers are known to choke over Gzip compressed stylesheets, so I'm wondering if that might happen with Javascript...

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Milchbazi
Junior WebHelper
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA

PostPosted: Wed Mar 12, 2003 7:11 am (14 years, 9 months ago) Reply with QuoteBack to Top

I have it not in a external file. Is one time in the head section the other time between the tables.

________________________________
TS Designs
___________________________
OfflineView User's ProfileFind all posts by MilchbaziSend Personal MessageVisit Poster's Website
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Wed Mar 12, 2003 10:10 am (14 years, 9 months ago) Reply with QuoteBack to Top

what error do you get in the browser?

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Milchbazi
Junior WebHelper
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA

PostPosted: Wed Mar 12, 2003 6:21 pm (14 years, 9 months ago) Reply with QuoteBack to Top

I don't get a error. It just not works.

In the auto-select drop down menu par example can you select what you want, but then it happens just nothing. And normaly you will come to an other part of the website.

The same with the bbcode-editor. Its like the editor from phpBB forum. But if I have gzcompression it doesn't work Rolling Eyes

Thx for your replies!
Milchbazi

________________________________
TS Designs
___________________________
OfflineView User's ProfileFind all posts by MilchbaziSend Personal MessageVisit Poster's Website
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Wed Mar 12, 2003 6:27 pm (14 years, 9 months ago) Reply with QuoteBack to Top

Which browser are you using? Could you give us a URL to try it out? It may be a browser related problem (I think a version of IE had a problem with gzipped pages)...

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Milchbazi
Junior WebHelper
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA

PostPosted: Thu Mar 13, 2003 3:17 am (14 years, 9 months ago) Reply with QuoteBack to Top

I use Internet Explorer 6 with Windows XP Professional. My Hoster is 1und1 - normally not the badest. Wink


Code:
<?php
ob_start();
ob_implicit_flush(0);

function can_gzip(){
    global $HTTP_ACCEPT_ENCODING;
    if (headers_sent() || connection_aborted()){
        return 0;
    }
    if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return "x-gzip";
    if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false) return "gzip";
    return 0;
}


function gz_output($level=9,$debug=1,$trim=1){
    $ENCODE = can_gzip();
    if ($ENCODE){
        print "\n<!-- Use compress $ENCODE -->\n";
        $Contents = ob_get_contents();
        ob_end_clean();

       if($trim){
         $Contents = str_replace("\n", ' ', $Contents);
         $Contents = str_replace("\r", ' ', $Contents);
         $Contents = preg_replace('=([[:space:]]{2,})=im', '', $Contents);
         $Contents = trim($Contents);
       }



        if ( COMPRESS_SHOW == 'true' ){ // Wenn debug nicht 0, dann ausgabe!
            $s = "<div align=\"center\"><font size\"1\" face=\"arial,verdana\" color=\"#868686\"><p>gzip compressed | zipped: ".sprintf ("%01.2f",((strlen(gzcompress($Contents,$level)))/1024))." kBytes | unzipped: ". sprintf ("%01.2f", ( (strlen($Contents) )/1024 ))." kBytes</font></div>";
            //$s .= "<br>Compressed length: ";
            $Contents .= $s;
        }

        header("Content-Encoding: $ENCODE");
        print "\x1f\x8b\x08\x00\x00\x00\x00\x00";
        $Size = strlen($Contents);
        $Crc = crc32($Contents);
        $Contents = gzcompress($Contents,$level);
        $Contents = substr($Contents, 0, strlen($Contents) - 4);

        print $Contents;
        print pack('V',$Crc);
        print pack('V',$Size);
        exit;
    }else{

        ob_end_flush();
        exit;
    }
}

#
#Then follows the normal HTML-Code - par example:
#
print"
<html>
<head>
<SCRIPT LANGUAGE=\"JavaScript\">
<!--
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}
// End -->
</SCRIPT>

</head>

<body>

<table border='0' cellpadding='0' width='0' cellspacing='0'>
<tr>
<td>

<form name='form'>
<select name='site' size=1 onChange='javascript:formHandler()'>
<option value=''>
<option value='http://www.metacrawler.com'>Metacrawler
<option value='http://www.altavista.digital.com'>Altavista
<option value='http://www.webcrawler.com'>Webcrawler
<option value='http://www.lycos.com'>Lycos
</select>
</form>


</td>
</tr>
</table>

</body>
</html>";

#
#Then gzip function to show the site
#
gz_output();
?>


Thats just a short example of it. Just written and so there might be errors in it. But never mind.

So. Now I put two sites on my hosted site where I get this errors.

You can find the sites with the same code from above here (with compression) and here (without compression)

PS: I tested it just now and it works without compression. So it must be the same error. But when I compress the site there comes a JavaScript error. But have just a look.


Thx a lot for your help Very Happy !
Milchbazi

PSS: www.dehogasaar.de is still in work and not finished yet. So don't be surprised if there is some text left. But a feedback were not bad. There will be a news-archiv later (for that the [...] Rolling Eyes JavaScript dropdown menu) and some other things. And last but not least: It's a full CMS (Content-Management-System).


Arrow PSSS: I just tested it with Opera (Version 6.02) and it doesn't work either.

________________________________
TS Designs
___________________________
OfflineView User's ProfileFind all posts by MilchbaziSend Personal MessageVisit Poster's Website
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Thu Mar 13, 2003 6:53 am (14 years, 9 months ago) Reply with QuoteBack to Top

One reason may be that the output is all on one line, which would probably cause problems with Javascript. I'm sort of wondering why you're using special code for gzip compression, since PHP often has this feature pre-installed... Question

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Thu Mar 13, 2003 11:31 am (14 years, 9 months ago) Reply with QuoteBack to Top

on the gziped example, mozilla gives the error "formHandler" is not defined...the problem is that the compressed version has no new lines, so the comment at the start of the java script is commenting out everything...

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Milchbazi
Junior WebHelper
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA

PostPosted: Thu Mar 13, 2003 2:44 pm (14 years, 9 months ago) Reply with QuoteBack to Top

Daniel wrote:
I'm sort of wondering why you're using special code for gzip compression, since PHP often has this feature pre-installed... Question


At first I wanted to thank you for your greate help! I think I will manage it now.

And secondly: I didn't know there is an other way to compress your site. So, how can you use the pre-installed feature? May be it's the easiest way, or not?


Thx a lot!
Milchbazi

________________________________
TS Designs
___________________________
OfflineView User's ProfileFind all posts by MilchbaziSend Personal MessageVisit Poster's Website
Milchbazi
Junior WebHelper
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA

PostPosted: Thu Mar 13, 2003 2:50 pm (14 years, 9 months ago) Reply with QuoteBack to Top

I justed tested it and it works if you have it not in one line. Thanks adam.

But please let me know about the pre-installed feature.

________________________________
TS Designs
___________________________
OfflineView User's ProfileFind all posts by MilchbaziSend Personal MessageVisit Poster's Website
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Thu Mar 13, 2003 4:45 pm (14 years, 9 months ago) Reply with QuoteBack to Top

The feature isn't available on all systems. Give us a link to your phpinfo() and I can tell you if it's installed.

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   


Go to page 1, 2  Next

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.08383 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme