Jump to content

[SOLVED] My host does not have Gzip compression, asked me to modify the .htaccess file instead...is this safe?


noesac

Recommended Posts

Unfortunately, the cPanel "Optimize Website" feature is disabled across our shared hosting environment as it can cause drastic server resource usage spikes with users enabling/disabling these settings incorrectly across all file types.

This feature is generally regarded as redundant as our shared hosting environment is compiled with the mod_deflate required for gzip at all times. This feature needs to be enabled via your website coding and with your .htaccess file. You may find the following link useful for achieving this:

http://blog.webhostingdiscussion.net/tag/enable-gzip-compression-via-htaccess



Basically the website they sent me to suggests adding the following text to the .htaccess file. Is this a a safe change to make? I'm always very cautious when it comes to modifying this file:

#compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml

SetOutputFilter DEFLATE

Link to comment
Share on other sites

Looks fine to me. That code appears to apply DEFLATE to all content sent using the text/html, text/plain and text/xml mime types and all files ending in HTML. That won't compress CSS or Javascript though. I suggest that you change it to:

#compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/js application/javascript

SetOutputFilter DEFLATE

Link to comment
Share on other sites

Thanks Rocky!!

I combined this with a combination of what you recommended on your site...in addition to more tweaks suggested by Google Page Speed and I boosted my site from 62/100 to 71/100:)

I had to reverse all my minify changes though as it caused all sorts of issues with javascript (although it's almost certainly an error on my part) but I'm still very happy with a 9 point boost.


UPDATE: I waited more time and reran the test, it's now 76/100

Link to comment
Share on other sites

Hi Rocky I've done some more testing, are you sure that mod will apply to Javascript and CSS?

I cleared the cache and shift + refreshed, and ran the Google Page Speed app again and it says the only things left without compression are the JS and CSS files.

Link to comment
Share on other sites

That's the code I used on one client's site to improve their YSlow! rating. I added it in their cPanel, not their .htaccess file though. Try the following:

#compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/js application/javascript

SetOutputFilter DEFLATE



or the preferred format:

#compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/js application/javascript

SetOutputFilter DEFLATE

Link to comment
Share on other sites

Whoa, adding:

#compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/js application/javascript

SetOutputFilter DEFLATE



to my htaccess, bumped me from 68 to 71 on Page Speed. Nice one!

There are a few other speed "issues" but not being too technical, the solutions offered by google are still over my head.

For example: "Serve static content from a cookieless domain"
It would be great if there was a more step by step guide to resolving these speed issues.

Link to comment
Share on other sites

  • 4 months later...
  • 4 months later...

Hello All,

Can anyone tell exactly which code have to be pasted in .httaccess file to increase speed of website? As my site is also slow now and no option of optimizing it in cpanel.

Please help.

Regards
Vilas

Link to comment
Share on other sites

  • 9 months later...
  • 1 year 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.

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