Problem serving static content gzipped
Problem serving static content gzipped
am 21.11.2007 03:38:26 von landemaine
Hello, I'm trying to serve as much gzipped content as possible on my
web site. I will gzip dynamic pages on the fly using PHP, and I plan
to gzip static content just one time, not to use much CPU, and serve
css.gz, .js.gz files, etc... So, I uploaded a test.html file and
a .css file that changes the color of the text to red. I gzipped the
css file:
%gzip style.css
I also uploaded an .htaccess file with this content:
RewriteEngine on
RewriteBase /gzip/
RewriteCond %{HTTP_ACCEPT_ENCODING} gzip
RewriteRule ^(([^.]+\.)+)css$ /$1css.gz
For now I'm not going to include any gunzipped style sheet, just to
make sure my browser picks the gzipped style sheet. I also uploaded a
phpinfo.php file to make sure I have mod_gzip. So, here's the list of
files I have:
- .htaccess
- style.css.gz
- test.html
- phpinfo.php
But when I open the test.html file: http://www.auriance.com/gzip/ the
style sheet isn't applied. If I upload a regular style.css file, it
works fine. It seems the Rewrite rules aren't taken into account. Do
you know how I could server the gzipped style sheet instead?
Thanks,
--
Charles
Re: Problem serving static content gzipped
am 21.11.2007 12:28:24 von HansH
"Charles" schreef in bericht
news:e48ef790-775d-40fb-870b-f05b6884c46b@n20g2000hsh.google groups.com...
> Hello, I'm trying to serve as much gzipped content as possible on my
> web site. I will gzip dynamic pages on the fly using PHP, and I plan
> to gzip static content just one time, not to use much CPU, and serve
> css.gz, .js.gz files, etc... So, I uploaded a test.html file and
> a .css file that changes the color of the text to red. I gzipped the
> css file:
>
> %gzip style.css
>
> I also uploaded an .htaccess file with this content:
>
> RewriteEngine on
> RewriteBase /gzip/
> RewriteCond %{HTTP_ACCEPT_ENCODING} gzip
> RewriteRule ^(([^.]+\.)+)css$ /$1css.gz
>
> For now I'm not going to include any gunzipped style sheet, just to
> make sure my browser picks the gzipped style sheet.
So far so good: style.css.gz is displayed in plain text by FF
However the uncompressed content seems smaller than the compressed file.
> I also uploaded a
> phpinfo.php file to make sure I have mod_gzip. So, here's the list of
> files I have:
> - .htaccess
> - style.css.gz
> - test.html
> - phpinfo.php
>
> But when I open the test.html file: http://www.auriance.com/gzip/ the
> style sheet isn't applied. If I upload a regular style.css file, it
> works fine. It seems the Rewrite rules aren't taken into account. Do
> you know how I could server the gzipped style sheet instead?
> RewriteRule ^(([^.]+\.)+)css$ /$1css.gz
In [^.] the dot is a wildcard 'any', so you made a class not-any that will
never match ...
Just changing to 'RewriteRule ^(([^\.]+\.)+)css$ /$1css.gz' might do,
but for stylesheets like my.first.styles.css ...
Just give a try to this, it should test for presence of the .gz too:
RewriteEngine on
RewriteBase /gzip/
# Just be sure, header might be (partial) upper case
RewriteCond %{HTTP_ACCEPT_ENCODING} gzip [NC]
# test for presence of .gz in same folder as requested file
RewriteCond %{SCRIPT_FILENAME}.gz -f
RewriteRule (.*) $1.gz
Be aware about issues with deflated style sheets and scripts.
By now I am assisting you in reinventing a pair of wheels ....
http://schroepl.net/projekte/mod_gzip/config.htm
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
HansH
Re: Problem serving static content gzipped
am 21.11.2007 16:33:09 von landemaine
On Nov 21, 8:28 am, "HansH" wrote:
> Just give a try to this, it should test for presence of the .gz too:
> RewriteEngine on
> RewriteBase /gzip/
> # Just be sure, header might be (partial) upper case
> RewriteCond %{HTTP_ACCEPT_ENCODING} gzip [NC]
> # test for presence of .gz in same folder as requested file
> RewriteCond %{SCRIPT_FILENAME}.gz -f
> RewriteRule (.*) $1.gz
Thanks Hans. I tried it but I didn't see a difference...However if, in
my XHTML file, I change:
To:
It works fine: http://gzip.auriance.com/test2.html
But then...No need to detect if the browser supports gzip. The 6
browsers I tested worked. Do you think it can be problematic to serve
gzipped static files by default?
> Be aware about issues with deflated style sheets and scripts.
Tell me...
Also, if I host a .css.gz file on a server that doesn't have mod_gzip,
is there a way to make it work? I tried on another server that doesn't
have mod_gzip: http://blyse.dreamhosters.com/
If I serve the file as application/gzip or application/x-gzip, I get a
download prompt instead of the actual content...
Any idea?
Thanks,
--
Charles.
Re: Problem serving static content gzipped
am 21.11.2007 23:29:24 von HansH
"Charles" schreef in bericht
news:75d00296-d1fe-4a96-8e63-373777d41acb@f13g2000hsa.google groups.com...
> On Nov 21, 8:28 am, "HansH" wrote:
>> Just give a try to this, it should test for presence of the .gz too:
>> RewriteEngine on
>> RewriteBase /gzip/
>> # Just be sure, header might be (partial) upper case
>> RewriteCond %{HTTP_ACCEPT_ENCODING} gzip [NC]
>> # test for presence of .gz in same folder as requested file
>> RewriteCond %{SCRIPT_FILENAME}.gz -f
>> RewriteRule (.*) $1.gz
>
> Thanks Hans. I tried it but I didn't see a difference...However if, in
> my XHTML file, I change:
>
> To:
>
> It works fine: http://gzip.auriance.com/test2.html
> But then...No need to detect if the browser supports gzip. The 6
> browsers I tested worked. Do you think it can be problematic to
> serve gzipped static files by default?
It is a violation of the rules by RFC2616; even if it works for you.
>> Be aware about issues with deflated style sheets and scripts.
> Tell me...
Most are probably historical incompatibities.
Anyway, what's the point deflating rather a small file?
Changes are the overhead of deflating makes it bigger!
Changes are it is only requested once per visit.
> Also, if I host a .css.gz file on a server that doesn't have mod_gzip,
> is there a way to make it work? I tried on another server that doesn't
> have mod_gzip: http://blyse.dreamhosters.com/
> If I serve the file as application/gzip or application/x-gzip, I get a
> download prompt instead of the actual content...
Ah ... reinventing the wheels for a good reason ;-)
The content type should always match the unmangled type,
like Content-Type: text/css
or Content-Type: text/html; charset=ISO-8859-1
and you have to enforce an _extra_ reponse header
Content-Encoding: gzip
Do get yourself FireFox and its LiveHTTPheader plugin and _view_ the
wonderful world of HTTP request and response headers.
HansH