Dr.Kameleon
Dr.Kameleon

Reputation: 22810

Compressing Javascript & CSS using Gzip

OK, the question may sound familiar - and I've read answers about it everywhere BUT (before you point me to some other answer) none of that has worked for me (htaccess modifications, gzip-ping beforehand, etc).

So, let me explain you the situation :

So, how do I enable JS/CSS gzip compression? (I don't really care even if the scripts are pre-compressed, they're 100% static anyway...)

Upvotes: 0

Views: 452

Answers (1)

Robin Castlin
Robin Castlin

Reputation: 10996

I have this through a controller that loads the css and javascript files in two different functions, then run this:

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
    ob_start("ob_gzhandler");
else ob_start();

// headers

// output

ob_end_flush();

Seems to be doing the trick for me.

Upvotes: 1

Related Questions