Jump to content

[SOLVED] How to enable Gzip compression


mowax

Recommended Posts

Hi all,

I'm trying to enable gzip compression to speed up my site, but have not been successful so far. I read that you can do it by adding this code to .htaccess in the root directory:

# BEGIN GZIP

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript

# END GZIP

I did this and used this tool to check it had worked: http://www.gidnetwork.com/tools/gzip-test.php

... but it didn't.

Is there something I am missing? I copied my .htaccess file below, can anyone tell me what I'm doing wrong?

# URL rewriting module activation

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteBase /

# URL rewriting rules
RewriteRule ^([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ product.php?id_product=$2$4 [L,E]
RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$ product.php?id_product=$1$3 [L,E]
RewriteRule ^([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ category.php?id_category=$1 [QSA,L,E]
RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ cms.php?id_cms=$1 [QSA,L,E]
RewriteRule ^([0-9]+)__([a-zA-Z0-9-]*)(.*)$ supplier.php?id_supplier=$1$3 [QSA,L,E]
RewriteRule ^([0-9]+)_([a-zA-Z0-9-]*)(.*)$ manufacturer.php?id_manufacturer=$1$3 [QSA,L,E]

# Catch 404 errors
ErrorDocument 404 /404.php


# BEGIN GZIP

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript

# END GZIP

Link to comment
Share on other sites

You could try:

php_value zlib.output_compression 16386

If that gives a 500 error, then your server is running PHP in CGI mode.

Your host should be really be able to tell you if compression is available, and how to turn it on.

If they're not interested (or don't know) they're probably not a good host to trust your business with.

Link to comment
Share on other sites


Your host should be really be able to tell you if compression is available, and how to turn it on.

If they're not interested (or don't know) they're probably not a good host to trust your business with.


They are probabaly just a reseller, and they dont know what they are doing....
Link to comment
Share on other sites

@ Pixel

Thanks I will try your code, can you tell me where I enter this? I have never run a script before. I have a scripting path, but I don't know how to access it. Do I use a web browser?

@ jhnstcks

Actually its Fasthosts ('UKs Number 1 Web Host'), and I'm going to leave them for a variety of reasons. This just adds to the list.

Can anyone recommend a UK host that doesn't take your money then treat you like a deaf mother-in-law?

Link to comment
Share on other sites


@ jhnstcks

Actually its Fasthosts ('UKs Number 1 Web Host'), and I'm going to leave them for a variety of reasons. This just adds to the list.

Can anyone recommend a UK host that doesn't take your money then treat you like a deaf mother-in-law?


I use a company called scotserve.co.uk They are very good not the cheapest but not the most expensive either but they are very reliable and quick. I pay £15+VAT for unmetered bandwidth, unlimited domains, email addresses and databases. My only limitation is my disk space is 2gb of space. But I am running 2 live shops, a blog, and a couple of test sites and I stlil havent used half of my disk space. They also run a server specifically for Prestashop, as some php versions don't work too well with it.

If you are interested email them at sales(at)scotserve(dot)co(dot)uk and tell him I sent you.
Link to comment
Share on other sites

It goes in your .htaccess file. If you don't know what that is (or don't have access to it) then you need to do a bit of finding-out and reading-up before you put a shop online.

Don't ever consider any 'host' who promises you 'unlimited' top-quality-all-you-can-eat for a dollar or three a month - it won't happen.

A well-maintained server, disk space, bandwidth and (especially) good pro-active 24/7 support cost money.

If you're serious about running a shop as a business (rather than a hobby), get yourself a good host with good support.

And - consequently - expect to pay a good amount.

Link to comment
Share on other sites

Firstly thanks John for a glowing report

Now, you have to understand there is a difference between mod_deflate and mod_gzip
It depends on what version of Apache you are running assuming you are not on an IIS server, mod_gzip for Apache 1.* and mode_deflate for Apache 2.*
This needs to be compiled into Apache so no amount of adding it to .htaccess files will make any difference if the host does not have it compiled - at this point I would point out that the stock out the box of Apache 2.* does not have mod_deflate installed.

Another point to consider is that many hosts will not allow you to override PHP values via .htaccess directives as this could be considered a security risk.
So adding "php_value zlib.output_compression 16386" to your .htaccess file assumes two things one is that zlib is compiled into php in the first place and secondly that they are allowing php values to be overridden

Overall you need to know what you are running on, what is compiled and available before you mess about with .htaccess files. Interestingly though the actual question is a hosting one IMO and is not something that should be fobbed off as a "script issue"

Link to comment
Share on other sites

Adding the suggested bits to the .htaccess file gives a 500 error, and having asked the host again they have now told me that gzip compression is not available on their shared hosting server. Guess its time to move on from fasthosts, thanks for all suggestions and recommendations.

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...
  • 2 weeks later...

In conjunction with Nethercott Constructions (rocky), I just completed a 2-part video that addresses enabling GZIP compression and browser caching in versions 1.4.x and 1.3.x. You can find the video at http://www.prestatraining.com/gzip-compression-browser-caching/. Notwithstanding issues from your host, this video should help, especially with version 1.3.x.

Link to comment
Share on other sites

  • 3 years later...

How can I enable compression to themes/default/cache?
this is what i get from PageSpeed Insights and gtmetrix.com:

Compressing the following resources with gzip could reduce their transfer size by 247.8KiB (73% reduction).

My prestashop version is: 1.5.6.2 (Default theme)

 

my current .htaccess code is this:

<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule . - [E=REWRITEBASE:/store/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url= [QSA,L]

# Images
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p//jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p///jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p////$1jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p////$4/$1jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p////$4/$5/$1jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p////$4/$5/$6/$1jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p////$4/$5/$6/$7/$1jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p////$4/$5/$6/$7/$8/$1jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/jpg [L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/c/jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/ [L]

# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^www.tekcenter.pt$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>


<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>


FileETag INode MTime Size
<IfModule mod_deflate.c>
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/css text/javascript application/javascript application/x-javascript
</IfModule>
</IfModule>  

Best regards.

Edited by majority (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...