Forum Moderators: phranque

Message Too Old, No Replies

I want to deliver huge javascript gzip compressed

What is necessary on Apache server

         

jetteroheller

6:39 pm on Jan 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am optimizing my layout since last October.

One of the main ideas is a mouse over in the navigation.
When the user puts the mouse over a navigation link,
over the content area is a directroy of what is behind the link shown.

Just right now, there are small directory files loaded into an iframe. But this takes time.

I have now the idea to put all this small directories into the javascript.

The javascript would be about 200 kB long.
Much to long to deliver it uncompressed.

A first study shows, that GZIP would bring it down to 30 kB,
that's no problem, the current js has 24 kb.

So I aks now, what's the best way for compresseion?

Are there today browsers not able to work with compressed files?

I have read about something in Apache to deliver

my.js (when the browser can not decompress)
my.js.gz (when the browser can decompress)

What to do, to make this on Apache server?

wildbest

7:55 pm on Jan 5, 2009 (gmt 0)

10+ Year Member



I'm doing this on PHP pages like that:

// submit gzip-ed data to user
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();

Make sure you put it just before any content is sent to browser!

jetteroheller

8:03 pm on Jan 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for this first reply.

This web site has about 40.000 visitors a month.

So I want, that I compress the javascript only at each upload and the server delivers the compressed javascript direct.

Maybe 4 updates a month, so only 4 times to compress on my computer instead of 40000 times on the server.

jetteroheller

9:58 pm on Jan 5, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just dicovered on an other site

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*
RewriteRule ^/(.*)\.js$ /$1.js.gz [L]
RewriteRule ^/(.*)\.css$ /$1.css.gz [L]
AddEncoding x-gzip text.gz

I added this to the .htaccess

and put

test.js
test.js.gz

on the server.

After this, I made a page with
<script src=test.js>

The access log files of the server show,
that at my tests with MSIE 7, Crome, Firefox,
always the uncompressed test.js was delivered
instead of, like expected, test.js.gz

Caterham

10:09 pm on Jan 5, 2009 (gmt 0)

10+ Year Member



Use a type map, they're designed for such purposes

[mrclay.org...]

jetteroheller

10:28 am on Jan 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I decided now for the most simple method

AddEncoding x-gzip .js

And I modified the upload routine of my self written CMS to compress all *.js files before upload.