0

i ve a fashion website & using wordpress. I want to Compress or Gzip or Deflate my CSS & JS files. i have tried many codes with .htaccess to compress but not working. Would any body help me please?

My phpinfo is http://deemasfashion.co.uk/1.php

below are the codes i have tried not not working. Few of them might be same but there is a difference in the syntax.

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

other code I have tried but not working...

<files *.css>
SetOutputFilter DEFLATE
</files>
<files *.js>
SetOutputFilter DEFLATE
</files>

I have also tried this code as well but no success.

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

This code is also not working

<FilesMatch "\.(html?|txt|css|js|php|pl)$">
SetOutputFilter DEFLATE
</FilesMatch>

Here is another code not working.

<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x- javascript application/javascript
</ifmodule>

Here is another code not working.

<IFModule mod_deflate.c>
<filesmatch "\.(js|css|html|jpg|png|php)$">
SetOutputFilter DEFLATE
</filesmatch>
</IFModule>

Here is another code not working.

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript text/javascript    application/javascript application/json
<FilesMatch "\.(css|js)$" >
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

Here is another code not working.

#Gzip - compress text, html, javascript, css, xml
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</ifmodule>
#End Gzip

Here is another code not working.

<Location />
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|gz2|sit|rar)$ no-gzip dont-vary
</Location> 
muhammad usman
  • 103
  • 1
  • 1
  • 3

1 Answers1

2

phpinfo doesn't show Apache's configuration unless it's a module - mod_status shows Apache's configuration, including loaded modules.

If you have mod_gzip installed, this should work:

mod_gzip_on Yes
mod_gzip_dechunk Yes

mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/javascript
mod_gzip_item_include mime ^application/xm.*
mod_gzip_item_include mime ^image/svg.*
mod_gzip_item_include mime ^application/(x-)?font-.*

(Note, the first two lines grab CSS and Javascript, but also anything with a "text" mime type)

I prefer mod_gzip to mod_deflate as

  1. GZip has a checksum, and uses the exact same compression as deflate.
  2. The configuration is a million times simpler. I still can't figure out if the Deflate configuration was intentionally difficult or an artifact of history.
  3. GZip is just as well supported in browsers, so no drawbacks other than the "overhead" of the checksum.
Chris S
  • 77,337
  • 11
  • 120
  • 212
  • thanks @Chris S i have used phpinfo(INFO_MODULES); in the [link](http://deemasfashion.co.uk/1.php) does this show the mod-status or there is another function. – muhammad usman Nov 05 '13 at 18:21
  • Please re-read the first line. Your PHP is run through CGI, not mod_php. – Chris S Nov 05 '13 at 18:27
  • .should i change the PHP run through mod_php or is there any way that I can Gzip the CSS and JS. Currently Gzip / Zlib is enabled in my Cpanel / Whm. My php pages are Gziped but only CSS and JS are not. – muhammad usman Nov 05 '13 at 20:07
  • please test this [Fashion](http://deemasfashion.com/latest-pakistani-anarkali-pishwas-frock-wear/shocking-pink-double-layer-frock/) – muhammad usman Nov 05 '13 at 20:11
  • Would you please check this now – muhammad usman Nov 05 '13 at 20:21
  • I'm sorry, but it has become apparent that you are an end user and not a system administrator. Please refer to your hosting company for support implementing your website on their servers. – Chris S Nov 05 '13 at 21:46
  • I mean that this code has worked nicely for me but i am not sure if Gzip working or Deflate working. Can you please let me know about this thanks @ChrisS. – muhammad usman Nov 08 '13 at 00:28
  • some OP or senior citizen referred me from stack overflow to serverfault by saying that this question is relevant to serverfault. :) – muhammad usman Nov 08 '13 at 00:30
  • I'm sorry but [SO] has a habit of telling people incorrect information about other [SE] sites. How do you know the code is working nicely if you don't know how to verify if GZip is working?? Install a HTTP Header plug-in for your browser and see what the `Content-Encoding:` of the server response says. LiveHTTPHeaders for [Firefox](http://livehttpheaders.mozdev.org/) or [Chrome](https://chrome.google.com/webstore/detail/live-http-headers/iaiioopjkcekapmldfgbebdclcnpgnlo?hl=en). – Chris S Nov 08 '13 at 01:19
  • Thanx... It worked for me.. I also have tried all options given in question. But, finally got this working. – Anuj TBE Oct 04 '15 at 16:19