Author |
Message |
Milchbazi
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA
|
Posted:
Tue Mar 11, 2003 11:17 pm (22 years, 1 month ago) |
  |
Hi,
is it possible to run a JavaScript with a GZip copressed PHP site? How?
Thx a lot,
Milchbazi |
________________________________ TS Designs
___________________________ |
|
     |
 |
adam
Forum Moderator & Developer

Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Wed Mar 12, 2003 1:03 am (22 years, 1 month ago) |
  |
that shouldn't be a problem at all...what's the problem you're having exactly? |
________________________________ It's turtles all the way down... |
|
     |
 |
drathbun
WebHelper

Joined: 01 Mar 2003
Posts: 69
Location: Texas
|
Posted:
Wed Mar 12, 2003 1:58 am (22 years, 1 month ago) |
  |
The question is irrelevant. 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 |
|
     |
 |
Milchbazi
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA
|
Posted:
Wed Mar 12, 2003 2:15 am (22 years, 1 month ago) |
  |
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
___________________________ |
|
     |
 |
Daniel
Team Member


Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Wed Mar 12, 2003 7:02 am (22 years, 1 month ago) |
  |
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... |
________________________________
 |
|
    |
 |
Milchbazi
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA
|
Posted:
Wed Mar 12, 2003 7:11 am (22 years, 1 month ago) |
  |
I have it not in a external file. Is one time in the head section the other time between the tables. |
________________________________ TS Designs
___________________________ |
|
     |
 |
adam
Forum Moderator & Developer

Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Wed Mar 12, 2003 10:10 am (22 years, 1 month ago) |
  |
what error do you get in the browser? |
________________________________ It's turtles all the way down... |
|
     |
 |
Milchbazi
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA
|
Posted:
Wed Mar 12, 2003 6:21 pm (22 years, 1 month ago) |
  |
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
Thx for your replies!
Milchbazi |
________________________________ TS Designs
___________________________ |
|
     |
 |
Daniel
Team Member


Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Wed Mar 12, 2003 6:27 pm (22 years, 1 month ago) |
  |
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)... |
________________________________
 |
|
    |
 |
Milchbazi
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA
|
Posted:
Thu Mar 13, 2003 3:17 am (22 years, 1 month ago) |
  |
I use Internet Explorer 6 with Windows XP Professional. My Hoster is 1und1 - normally not the badest.
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 !
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 [...] JavaScript dropdown menu) and some other things. And last but not least: It's a full CMS (Content-Management-System).
PSSS: I just tested it with Opera (Version 6.02) and it doesn't work either. |
________________________________ TS Designs
___________________________ |
|
     |
 |
Daniel
Team Member


Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Thu Mar 13, 2003 6:53 am (22 years, 1 month ago) |
  |
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...  |
________________________________
 |
|
    |
 |
adam
Forum Moderator & Developer

Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Thu Mar 13, 2003 11:31 am (22 years, 1 month ago) |
  |
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... |
|
     |
 |
Milchbazi
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA
|
Posted:
Thu Mar 13, 2003 2:44 pm (22 years, 1 month ago) |
  |
Daniel wrote: | I'm sort of wondering why you're using special code for gzip compression, since PHP often has this feature pre-installed...  |
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
___________________________ |
|
     |
 |
Milchbazi
Junior WebHelper


Joined: 11 Mar 2003
Posts: 15
Location: NH, USA
|
Posted:
Thu Mar 13, 2003 2:50 pm (22 years, 1 month ago) |
  |
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
___________________________ |
|
     |
 |
Daniel
Team Member


Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Thu Mar 13, 2003 4:45 pm (22 years, 1 month ago) |
  |
The feature isn't available on all systems. Give us a link to your phpinfo() and I can tell you if it's installed. |
________________________________
 |
|
    |
 |
|