0

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 :

  • My website is CodeIgniter-based
  • I'm using XAMPP on Mac (for development purposes), so my actual testing address is something like http://localhost/~drkameleon/mysitename
  • The only .htaccess file I've edited (and that, only for CI-oriented rewritting) resides on the very same directory as my CI installation

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...)

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I create a controller which loads all the files, and outputs them together with this code.
Hmm... I still don't get it - I'm not such a guru with HTTP Headers, etc. Could you please give me more complete example? I'm using several "external" .js scripts, I'm importing within a View the usual way (<script></script>). Where should the controller be called? Does it simply echo the .js files' content? (after ob_start I mean...)
OK, I finally made it work - although I'm definitely not sure how I did it (lol) - thought I had tried that one before (perhaps it was some issue with the cache not having being cleared before re-testing? - don't know...) Pff... Thanks a lot, anyway, buddy! ;-)
Personally, I just have an array of the paths to the files, loop with readfile() and only include one "js" file which is the php controller outputting everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.