Pre compressed css and javascript

Pre compressed css and javascript

am 04.10.2010 15:31:25 von ben short

Hi,

I have configured my httpd instance to serve pre-compressed css and
java script. But I have two issues.

My httpd configuration is as follows.

RewriteEngine On
RewriteLog "logs/rewrite.log"
RewriteLogLevel 5

AddEncoding gzip .gz

RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari

# is the request for a js or css file?
RewriteCond %{REQUEST_FILENAME} ^(.*).(js|css)$
# is there a gziped version of the file?
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule ^(.*)$ $1.gz [QSA,L]

Issue 1 is that the last RewriteCond never matches even though I can
request the gz version directly from the browser. Odly I have no non
gzipped version of the file on the server so requesting it results in
me being served the gzipped version.

192.168.1.46 - - [04/Oct/2010:14:25:34 +0100]
[www.journeycheck.southwesttrains.co.uk/sid#973c5d8][rid#98a b4c0/initial]
(2) init rewrite engine with requested uri /southwesttrains/main.css
192.168.1.46 - - [04/Oct/2010:14:25:34 +0100]
[www.journeycheck.southwesttrains.co.uk/sid#973c5d8][rid#98a b4c0/initial]
(3) applying pattern '/favicon.ico' to uri '/southwesttrains/main.css'
192.168.1.46 - - [04/Oct/2010:14:25:34 +0100]
[www.journeycheck.southwesttrains.co.uk/sid#973c5d8][rid#98a b4c0/initial]
(3) applying pattern '^(.*)$' to uri '/southwesttrains/main.css'
192.168.1.46 - - [04/Oct/2010:14:25:34 +0100]
[www.journeycheck.southwesttrains.co.uk/sid#973c5d8][rid#98a b4c0/initial]
(4) RewriteCond: input='gzip,deflate' pattern='gzip' => matched
192.168.1.46 - - [04/Oct/2010:14:25:34 +0100]
[www.journeycheck.southwesttrains.co.uk/sid#973c5d8][rid#98a b4c0/initial]
(4) RewriteCond: input='/southwesttrains/main.css'
pattern='^(.*).(js|css)$' => matched
192.168.1.46 - - [04/Oct/2010:14:25:34 +0100]
[www.journeycheck.southwesttrains.co.uk/sid#973c5d8][rid#98a b4c0/initial]
(4) RewriteCond: input='/southwesttrains/main.css.gz' pattern='-f' =>
not-matched
192.168.1.46 - - [04/Oct/2010:14:25:34 +0100]
[www.journeycheck.southwesttrains.co.uk/sid#973c5d8][rid#98a b4c0/initial]
(1) pass through /southwesttrains/main.css


Issue 2 is that although the browser has the following warning when
loading the page.

FireFox:

Warning: The stylesheet
http://www.journeycheck.southwesttrains.co.uk/southwesttrain s/main.css
was loaded as CSS even though its MIME type, "application/x-gzip", is
not "text/css".
Source File: http://www.journeycheck.southwesttrains.co.uk/southwesttrain s/index.html
Line: 0

Chrome:

Resource interpreted as stylesheet but transferred with MIME type
application/x-gzip.


Any help would be appreciated.

Regards

Ben

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 15:55:01 von Eric Covener

> RewriteCond %{REQUEST_FILENAME}.gz -f

in vhost context, you have to add the document root in yourself, since
the request hasn't actually been mapped to a file yet.

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 16:07:10 von ben short

Hi Eric,

I have the DocumentRoot in my vhost. Sorry I omitted some of the configurat=
ion.

Ben



On 4 October 2010 14:55, Eric Covener wrote:
>> RewriteCond %{REQUEST_FILENAME}.gz -f
>
> in vhost context, you have to add the document root in yourself, since
> the request hasn't actually been mapped to a file yet.
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project=
..
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> =A0 " =A0 from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 16:26:31 von Eric Covener

On Mon, Oct 4, 2010 at 10:07 AM, Ben Short wrote:
> Hi Eric,
>
> I have the DocumentRoot in my vhost. Sorry I omitted some of the configuration.

I meant on the RewriteCond itself. REQUEST_FILENAME is just the URI
unless your rules are in or .htaccess, because the request
has not been mapped to any filename yet.

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 16:38:18 von ben short

Eric,

Ah I see what you mean changing

RewriteCond %{REQUEST_FILENAME}.gz -f

to

RewriteCond /usr/local/apache2/docs/www.journeycheck.southwesttrains.co. uk/=
%{REQUEST_FILENAME}.gz
-f

works.

Thank you

Ben

On 4 October 2010 15:26, Eric Covener wrote:
> On Mon, Oct 4, 2010 at 10:07 AM, Ben Short wrote:
>> Hi Eric,
>>
>> I have the DocumentRoot in my vhost. Sorry I omitted some of the configu=
ration.
>
> I meant on the RewriteCond itself. =A0REQUEST_FILENAME is just the URI
> unless your rules are in or .htaccess, because the request
> has not been mapped to any filename yet.
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project=
..
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> =A0 " =A0 from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 17:18:45 von Joost de Heer

On 10/04/2010 03:55 PM, Eric Covener wrote:
>> RewriteCond %{REQUEST_FILENAME}.gz -f
>
> in vhost context, you have to add the document root in yourself, since
> the request hasn't actually been mapped to a file yet.

If I understand the docs correctly, this can also be fixed with
%{LA-U:REQUEST_FILENAME}

Joost

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 17:19:40 von i.galic

> Eric,
>=20
> Ah I see what you mean changing
>=20
> RewriteCond %{REQUEST_FILENAME}.gz -f
>=20
> to
>=20
> RewriteCond
> /usr/local/apache2/docs/www.journeycheck.southwesttrains.co. uk/%{REQUEST_=
FILENAME}.gz
> -f


First off:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f


But.. what about Options +MultiViews?
http://httpd.apache.org/docs/current/content-negotiation.htm l

?
=20
> works.
>=20
> Thank you
>=20
> Ben
>=20
> On 4 October 2010 15:26, Eric Covener wrote:
> > On Mon, Oct 4, 2010 at 10:07 AM, Ben Short
> wrote:
> >> Hi Eric,
> >>
> >> I have the DocumentRoot in my vhost. Sorry I omitted some of the
> configuration.
> >
> > I meant on the RewriteCond itself.  REQUEST_FILENAME is just the
> URI
> > unless your rules are in or .htaccess, because the
> request
> > has not been mapped to any filename yet.
> >
> >
> ------------------------------------------------------------ ---------
> > The official User-To-User support forum of the Apache HTTP Server
> Project.
> > See for more info.
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> >   "   from the digest: users-digest-unsubscribe@httpd.apache.=
org
> > For additional commands, e-mail: users-help@httpd.apache.org
> >
> >
>=20
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server
> Project.
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org

--=20
Igor Galić

Tel: +43 (0) 664 886 22 883
Mail: i.galic@brainsware.org
URL: http://brainsware.org/

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 17:36:14 von ben short

Joost,

That also works for me. Thank you

2010/10/4 Igor Galić :
>
>> Eric,
>>
>> Ah I see what you mean changing
>>
>> RewriteCond %{REQUEST_FILENAME}.gz -f
>>
>> to
>>
>> RewriteCond
>> /usr/local/apache2/docs/www.journeycheck.southwesttrains.co. uk/%{REQUEST=
_FILENAME}.gz
>> -f
>
>
> First off:
>
> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f
>
>
> But.. what about Options +MultiViews?
> http://httpd.apache.org/docs/current/content-negotiation.htm l
>
> ?
>
>> works.
>>
>> Thank you
>>
>> Ben
>>
>> On 4 October 2010 15:26, Eric Covener wrote:
>> > On Mon, Oct 4, 2010 at 10:07 AM, Ben Short
>> wrote:
>> >> Hi Eric,
>> >>
>> >> I have the DocumentRoot in my vhost. Sorry I omitted some of the
>> configuration.
>> >
>> > I meant on the RewriteCond itself.  REQUEST_FILENAME is just the
>> URI
>> > unless your rules are in or .htaccess, because the
>> request
>> > has not been mapped to any filename yet.
>> >
>> >
>> ------------------------------------------------------------ ---------
>> > The official User-To-User support forum of the Apache HTTP Server
>> Project.
>> > See for more info.
>> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> >   "   from the digest: users-digest-unsubscribe@httpd.apache=
..org
>> > For additional commands, e-mail: users-help@httpd.apache.org
>> >
>> >
>>
>> ------------------------------------------------------------ ---------
>> The official User-To-User support forum of the Apache HTTP Server
>> Project.
>> See for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>    "   from the digest: users-digest-unsubscribe@httpd.ap=
ache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>
> --
> Igor Galić
>
> Tel: +43 (0) 664 886 22 883
> Mail: i.galic@brainsware.org
> URL: http://brainsware.org/
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project=
..
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.or=
g
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 04.10.2010 17:41:00 von Eric Covener

> But.. what about Options +MultiViews?
> http://httpd.apache.org/docs/current/content-negotiation.htm l

FWIW I think you need the "MutlViewsMatch any" and make sure your
requests are all for "foo" and not "foo.js", otherwise it doesn't kick
in (from my recollection).

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 06.10.2010 14:00:40 von ben short

I got it all working. My configuration is shown below. Thanks for the help.


ServerAdmin ben.short@nexusalpha.com
DocumentRoot
"/usr/local/apache2/docs/www.journeycheck.southwesttrains.co .uk/"
ServerName www.journeycheck.southwesttrains.co.uk

RewriteEngine On
RewriteLog "logs/rewrite.log"
RewriteLogLevel 5

RewriteCond %{REQUEST_URI} !^(.*)/resources/*
RewriteRule ^(.*)$ /southwesttrains$1 [QSA,NC,PT,L]

RewriteCond %{REQUEST_URI} !^(.*).(js|css)$
RewriteRule ^(.*)$ $1 [QSA,L]

RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{HTTP_USER_AGENT} !Safari
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f

RewriteCond %{REQUEST_URI} !^(.*).js$
AddEncoding gzip .gz
AddType application/x-javascript .gz
RewriteRule ^(.*)$ $1.gz [QSA,L]

RewriteCond %{REQUEST_URI} !^(.*).css$
AddEncoding gzip .gz
AddType text/css .gz
RewriteRule ^(.*)$ $1.gz [QSA,L]

/usr/local/apache2/docs/www.journeycheck.southwesttrains.co. uk>
Options +MultiViews
AllowOverride None
Order allow,deny
allow from all


ErrorLog "logs/www.journeycheck.southwesttrains.co.uk-error_log"
CustomLog
"logs/www.journeycheck.southwesttrains.co.uk-access_log" common

ExpiresActive On
ExpiresDefault "access plus 1 days"
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/png "access plus 1 days"


JKMount /* web4
JKUnmount /resources/* web4
JKUnmount /manager web4





On 4 October 2010 16:41, Eric Covener wrote:
>> But.. what about Options +MultiViews?
>> http://httpd.apache.org/docs/current/content-negotiation.htm l
>
> FWIW I think you need the "MutlViewsMatch any" and make sure your
> requests are all for "foo" and not "foo.js", otherwise it doesn't kick
> in (from my recollection).
>
> ------------------------------------------------------------ ---------
> The official User-To-User support forum of the Apache HTTP Server Project=
..
> See for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> =A0 " =A0 from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Pre compressed css and javascript

am 08.10.2010 09:51:59 von ben short

After more investigation the previous configuration did not actually
work correctly. The following does.

AddEncoding gzip .jgz
AddType application/javascript .jgz
AddEncoding gzip .cgz
AddType text/css .cgz

RewriteCond %{REQUEST_URI} ^(.*).js$
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.jgz -f
RewriteCond %{HTTP_USER_AGENT} !Safari [OR]
RewriteCond %{HTTP_USER_AGENT} Chrome
RewriteRule ^(.*)$ $1.jgz [QSA,L]

RewriteCond %{REQUEST_URI} ^(.*).css$
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.cgz -f
RewriteCond %{HTTP_USER_AGENT} !Safari [OR]
RewriteCond %{HTTP_USER_AGENT} Chrome
RewriteRule ^(.*)$ $1.cgz [QSA,L]




On 6 October 2010 13:00, Ben Short wrote:
> I got it all working. My configuration is shown below. Thanks for the hel=
p.
>
>
> =A0 =A0 =A0 =A0ServerAdmin ben.short@nexusalpha.com
> =A0 =A0 =A0 =A0DocumentRoot
> "/usr/local/apache2/docs/www.journeycheck.southwesttrains.co .uk/"
> =A0 =A0 =A0 =A0ServerName www.journeycheck.southwesttrains.co.uk
>
> =A0 =A0 =A0 =A0RewriteEngine On
> =A0 =A0 =A0 =A0RewriteLog "logs/rewrite.log"
> =A0 =A0 =A0 =A0RewriteLogLevel 5
>
> =A0 =A0 =A0 =A0RewriteCond %{REQUEST_URI} !^(.*)/resources/*
> =A0 =A0 =A0 =A0RewriteRule ^(.*)$ /southwesttrains$1 [QSA,NC,PT,L]
>
> =A0 =A0 =A0 =A0RewriteCond %{REQUEST_URI} !^(.*).(js|css)$
> =A0 =A0 =A0 =A0RewriteRule ^(.*)$ $1 [QSA,L]
>
> =A0 =A0 =A0 =A0RewriteCond %{HTTP:Accept-encoding} gzip
> =A0 =A0 =A0 =A0RewriteCond %{HTTP_USER_AGENT} !Safari
> =A0 =A0 =A0 =A0RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.gz -f
>
> =A0 =A0 =A0 =A0RewriteCond %{REQUEST_URI} !^(.*).js$
> =A0 =A0 =A0 =A0AddEncoding gzip .gz
> =A0 =A0 =A0 =A0AddType application/x-javascript .gz
> =A0 =A0 =A0 =A0RewriteRule ^(.*)$ $1.gz [QSA,L]
>
> =A0 =A0 =A0 =A0RewriteCond %{REQUEST_URI} !^(.*).css$
> =A0 =A0 =A0 =A0AddEncoding gzip .gz
> =A0 =A0 =A0 =A0AddType text/css .gz
> =A0 =A0 =A0 =A0RewriteRule ^(.*)$ $1.gz [QSA,L]
>
> =A0 =A0 =A0 =A0 > /usr/local/apache2/docs/www.journeycheck.southwesttrains.co. uk>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Options +MultiViews
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0AllowOverride None
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Order allow,deny
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0allow from all
> =A0 =A0 =A0 =A0
>
> =A0 =A0 =A0 =A0ErrorLog "logs/www.journeycheck.southwesttrains.co.uk-erro=
r_log"
> =A0 =A0 =A0 =A0CustomLog
> "logs/www.journeycheck.southwesttrains.co.uk-access_log" common
>
> =A0 =A0 =A0 =A0ExpiresActive On
> =A0 =A0 =A0 =A0ExpiresDefault "access plus 1 days"
> =A0 =A0 =A0 =A0ExpiresByType image/gif "access plus 1 days"
> =A0 =A0 =A0 =A0ExpiresByType image/png "access plus 1 days"
>
>
> =A0 =A0 =A0 =A0JKMount /* web4
> =A0 =A0 =A0 =A0JKUnmount /resources/* web4
> =A0 =A0 =A0 =A0JKUnmount /manager web4
>
>

>
>
>
> On 4 October 2010 16:41, Eric Covener wrote:
>>> But.. what about Options +MultiViews?
>>> http://httpd.apache.org/docs/current/content-negotiation.htm l
>>
>> FWIW I think you need the "MutlViewsMatch any" and make sure your
>> requests are all for "foo" and not "foo.js", otherwise it doesn't kick
>> in (from my recollection).
>>
>> ------------------------------------------------------------ ---------
>> The official User-To-User support forum of the Apache HTTP Server Projec=
t.
>> See for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> =A0 " =A0 from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
>

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org