Jump to content

Speed Up your Site and compression with htaccess file


Recommended Posts

Hey everyone somthing really usfull and handy to speed up your site caching and compressing

Just add the codes to your htacces file.

also if you need help let me know :)

Add to .htaccess:

Header unset Pragma FileETag None Header unset ETag

 

Cache-Control and Expires headers

<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf|pdf|flv|mp3)$"> <IfModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 14 days" Header set Cache-Control "public" </IfModule> </FilesMatch> <FilesMatch "\.(html|htm|xml|txt|xsl)$"> Header set Cache-Control "max-age=7200, must-revalidate" </FilesMatch>

 

Add to .htaccess:

Gzip compression with mod_deflate module

<IfModule mod_mime.c>

AddType application/x-javascript .js

AddType text/css .css

</IfModule>

<IfModule mod_deflate.c>

AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript

<IfModule mod_setenvif.c>

BrowserMatch ^Mozilla/4 gzip-only-text/html

BrowserMatch ^Mozilla/4\.0[678] no-gzip

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</IfModule>

<IfModule mod_headers.c>

Header append Vary User-Agent env=!dont-vary

</IfModule>

</IfModule>

What this code does it activate compression of all files except these files archives, images, multimedia files, etc.

SetOutputFilter DEFLATE

<IfModule mod_setenvif.c>

SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary

</IfModule>

 

Sorce COde from howtounix.info

  • Like 9
Link to comment
Share on other sites

  • 2 weeks later...

I did what was mentioned above. And I think it works, but not by much.

 

My GZIP compression shows it's very slow by looking at Gtmetrix.com

 

How would I compress the rest?

Edited by generalexperts (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 2 weeks later...
  • 2 weeks later...

Hey everyone somthing really usfull and handy to speed up your site caching and compressing

Just add the codes to your htacces file.

also if you need help let me know :)

Add to .htaccess:

Header unset Pragma FileETag None Header unset ETag

 

Cache-Control and Expires headers

<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf|pdf|flv|mp3)$"> <IfModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 14 days" Header set Cache-Control "public" </IfModule> </FilesMatch> <FilesMatch "\.(html|htm|xml|txt|xsl)$"> Header set Cache-Control "max-age=7200, must-revalidate" </FilesMatch>

 

Add to .htaccess:

Gzip compression with mod_deflate module

<IfModule mod_mime.c>

AddType application/x-javascript .js

AddType text/css .css

</IfModule>

<IfModule mod_deflate.c>

AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript

<IfModule mod_setenvif.c>

BrowserMatch ^Mozilla/4 gzip-only-text/html

BrowserMatch ^Mozilla/4\.0[678] no-gzip

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

</IfModule>

<IfModule mod_headers.c>

Header append Vary User-Agent env=!dont-vary

</IfModule>

</IfModule>

What this code does it activate compression of all files except these files archives, images, multimedia files, etc.

SetOutputFilter DEFLATE

<IfModule mod_setenvif.c>

SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary

</IfModule>

 

Sorce COde from howtounix.info

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)

 

Best regards.

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

@generalexperts - the response time of your store is slow in general. I would test if there different cache settings if you can get out more or change hosting. Don't ask me why but with my theme disabling Minify HTML after "smarty compile" execution and Keep inline JavaScript in HTML as original made a huge difference in response time.

Greetz, Trip

Link to comment
Share on other sites

Thanks Spidersiteme!

 

My score went from 88% to 94% on pagespeed.

 

I only added this at the bottom of the htaccess file:

<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>

SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
</IfModule>

the line "Header unset Pragma FileETag None Header unset ETag" gave an internal server error in my case, but I am very happy with the result that it gave with the code above here.

 

Thanks again!

  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

hi,

My website link is lelobooks.com

 

i have done almost all of the changes in the website but still my website my website is taking approx 5 + seconds to load. Please suggest me something.

 

Thanks,

 

According to this report, there are still improvements to be made: http://gtmetrix.com/reports/www.lelobooks.com/2mpEbwr0

But even then, your page generation time is high. Which hosting do you use?

Link to comment
Share on other sites

In my experience, optimalization is a long and ongoing process. I have my own topic here where I am struggeling with speed as well (although speed has much improved lately). There are several other topics on this forum about speed related issues that are unanswered. Maybe this forum is not even the place to be. Maybe some hosting-forum or so could provide better help.

 

I can however advise you to start optimizing your images, of which some seem to be quite big. Start reducing the total size of your page. And installing Varnish, Nginx and APC on your VPS is in my opinion a must. And according to the size of your shop you should take the appropiate server resources as well (of which I still cannot exactly tell what is appropiate, but hosting a Prestashop with, lets say, 10.000 products in 3000 categories shouldn't be on a shared hosting).

 

Happy selling!

Link to comment
Share on other sites

  • 2 months later...

Hi,

 

How do I set the expiration date for images I added already the mentioned code to my .htaccess but Google still complain about this:

Leverage browser caching
Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.
 
Cheers,
/Alex
Link to comment
Share on other sites

  • 1 month later...

+1 for ALMAJ and Hardwell

 

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)

 

Best regards.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I tried this but it doesnt change anything still the same result on gtmetrix.

I added these lines in my htaccess file

Header unset Pragma
FileETag None
Header unset ETag

<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf|pdf|flv|mp3)$">
<IfModule mod_expires.c>
 ExpiresActive on
 ExpiresDefault "access plus 14 days"
 Header set Cache-Control "public"
</IfModule>
</FilesMatch>
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
 Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

but still get:

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

http://xxx.com/img/logo.jpg (expiration not specified)
http://xxx.com/modules/imageslider/views/img/1-slideImage_3.jpg (expiration not specified)
http://xxx.com/themes/xxx/cache/v_0_0d00e8f914efc27bbda83b72453ba6e7.js (expiration not specified)
http://xxx.com/themes/xxx/cache/v_0_9d318a19584dfc18ee2c0294695ad584_all.css (expiration not specified)
http://connect.facebook.net/en_US/all.js (20 minutes)
Edited by thepan (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hello,

 

Do you know how to do it for Nginx?

 

Or you know any post that talk about it?

 

I have enabled Gzip in Nginx, but I do not know how to configure it with Prestashop.

 

Best regards

 

 

        ##
        # Gzip Settings
        ##


        gzip on;
        gzip_disable "MSIE [1-6].(?!.*SV1)";
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript $
Edited by jhd (see edit history)
Link to comment
Share on other sites

  • 1 month later...

hello 
 
i am running abhishekproducts.in
 
and on page insight i get eh following after trying the above code
 
http://abhishekproducts.in/…v_21_fabd4c2f1733c0f44832f54b3d1530b5.js could save 151.5KiB (69% reduction).

 

and  the header for the same js shows this 

 

Response header for uncompresses JS

  1. Accept-Ranges:
    none
  2. Cache-Control:
    max-age=604800
  3. Connection:
    keep-alive
  4. Content-Length:
    278756
  5. Content-Type:
    application/javascript
  6. Date:
    Wed, 22 Oct 2014 20:41:27 GMT
  7. Expires:
    Wed, 29 Oct 2014 20:41:27 GMT
  8. Last-Modified:
    Wed, 22 Oct 2014 19:49:25 GMT
  9. Server:
    nginx
  10. Vary:
    Accept-Encoding
 
 
Where as the compress CSS shows this
  1. Cache-Control:
    max-age=604800
  2. Connection:
    keep-alive
  3. Content-Encoding:
    gzip<------------------------------------look at this
  4. Content-Type:
    text/css
  5. Date:
    Wed, 22 Oct 2014 20:41:26 GMT
  6. Expires:
    Wed, 29 Oct 2014 20:41:26 GMT
  7. Last-Modified:
    Wed, 22 Oct 2014 19:49:22 GMT
  8. Server:
    nginx
  9. Transfer-Encoding:
    chunked
  10. Vary:
    Accept-Encoding
  11. Vary:
    Accept-Encoding
 
 
so as you see the JS is not getting compresses where as the CSS and other html files are getting compresses.
 
 
Any one any ideas on this ?
Link to comment
Share on other sites

  • 3 months later...

can someone let me know if this code is ok to put at bottom of htaccess file? thanks for the help @havana and @Spidersiteme

 

<IfModule mod_mime.c>
 
 <filesmatch ".html.gz$">
   ForceType text/html
   FileETag None
 </filesmatch>
  AddEncoding gzip .gz
  AddType text/html .gz
 
AddType application/x-javascript .js
AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
SetEnvIfNoCase Request_URI .gz$ no-gzip
 
AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
  Header set Vary "Accept-Encoding, Cookie"
  Header set Cache-Control 'max-age=3600, must-revalidate'
 
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
<ifmodule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html A3600
</ifmodule>
SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
</IfModule>

also i assume the code i just posted goes under this?

 

RewriteRule [0-9/]+/[0-9]+\.jpg$ - [F]
# end ~ module watermark section
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

I have added your first line to the .htaccess and

 

"

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log."

 

I'm afraid to do the rest <_<

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

Thanks Spidersiteme!

 

My score went from 88% to 94% on pagespeed.

 

I only added this at the bottom of the htaccess file:

<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>

SetOutputFilter DEFLATE
<IfModule mod_setenvif.c>
SetEnvIfNoCase Request_URI \.(?:rar|zip)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:gif|jpg|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:avi|mov|mp4)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
</IfModule>

the line "Header unset Pragma FileETag None Header unset ETag" gave an internal server error in my case, but I am very happy with the result that it gave with the code above here.

 

Thanks again!

 

Wow! This code really works well! Just wondering why this thing not have been implemented in the first place

Link to comment
Share on other sites

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

Hi, I am trying to improve my site speed and then found this topic about how to speed up site and compression with htaccess file.

 

Although the subject is old but it should help me to improve my site. However I didn't succeed to utilize the codes in htaccess file.

Could anyone provide a fresh code for Prestashop 1.6 that I could add to my htaccess file?

 

Thanks

Link to comment
Share on other sites

  • 3 months later...

Can you look at my site also?

Adjsuting CCC didnt helped too much still 15+ sec to load the site. www.10r.hu

The system shows the siteURL.php and language.php loads too long.

 

Also config, init, initheader, initcontent loads too long too.

 

Any idea to fix these?

Thanks a lot

Link to comment
Share on other sites

  • 1 year later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...