/    Sign up×
Community /Pin to ProfileBookmark

Forced gzipping PHP fails in IE

Works in all other browsers (of course) but is failing in IE?

Fails with errors
[COLOR=red]
SWFObject is undefined line 366 / char 1
SWFObject is undefined line 371 / char 1
Object Expected line 33 / char 1[/COLOR]

And sometimes
[COLOR=red]Object Expected line 32 / char ???[/COLOR]

Using this script in this way

[code=html]<script type=”text/javascript” src=”gzip.php?cache=true&exp=256&f0=js/swfobject.js&f1=js/lytebox.js&f2=js/jquery.js&f3=js/compress.js&f4=js/accordion.js”></script>
[/code]

and here is the source php

[code=php]
$expiry = 3;
if($_GET[“exp”]) {
$expiry = $_GET[“exp”];
}
for($i=0; $i<100; $i++) {
$file = $_GET[“f$i”];
if($file) {
if(file_exists($file)) {
$ext = strtolower(substr($file, strrpos($file, “.”)));
if($ext == “.css” || $ext == “.js”) {
$content .= file_get_contents($file);
if(!$mytype) {
$mytype = $ext;
}
}
} else {
$content .= “// FILE NOT FOUND ‘$file’nn”;
}
} else {
break;
}
}
if($_GET[“cache”]) {
$expiresOffset = 3600 * 24 * $expiry;
} else {
$expiresOffset = 20;
}
if($mytype == “.css”) {
$type = “text/css”;
} elseif($mytype == “.js”) {
$type = “text/javascript”;
} else {
die();
}
header(“Content-type: $type; charset: UTF-8”);
header(“Content-Encoding: gzip”);
header(“Expires: ” . gmdate(“D, d M Y H:i:s”, time() + $expiresOffset) . ” GMT”);
$compressed = gzencode($content, 9, FORCE_GZIP);
echo $compressed;

ob_start(‘ob_gzhandler’);
header(“Content-type: $type; charset: UTF-8”);
echo $content;
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ehimeauthorMay 08.2009 — I hates the OB handler at the end......

figure.....

?

This script also does not assign expire headers to my CSS/JS objects for some reason,

even though it should, in theory? I must be missing something here....
Copy linkTweet thisAlerts:
@NogDogMay 09.2009 — If you are going to use ob_start() with the ob_gzhandler, then it makes no sense (to me, anyway) to also gzencode() the output. If they both worked, then you would be zipping the already zipped. Try commenting out these 2 lines:
[code=php]
// $compressed = gzencode($content, 9, FORCE_GZIP);
// echo $compressed;
[/code]

This lets the ob_gzhandler do all the content negotiation with the browser and decide whether or not to zip the output.
×

Success!

Help @ehime spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...