php - Gzip Compression and leverage Browser Cache Not working for my store -


i trying optimize store, have added gzip code , leverage browser cache code in .htaccess file:

# leverage browser caching using mod_expires # <ifmodule mod_expires.c>     expiresactive on     expiresbytype image/jpg "access plus 1 year"     expiresbytype image/jpeg "access plus 1 year"     expiresbytype image/gif "access plus 1 year"     expiresbytype image/png "access plus 1 year"     expiresbytype text/css "access plus 1 month"     expiresbytype application/pdf "access plus 1 month"     expiresbytype text/x-javascript "access plus 1 month"     expiresbytype application/x-shockwave-flash "access plus 1 month"     expiresbytype image/x-icon "access plus 1 year"     expiresdefault "access plus 2 days" </ifmodule> # end of leverage browser caching using mod_expires #  # leverage browser caching using mod_headers # <ifmodule mod_headers.c>     <filesmatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">         header set expires "wed, 15 apr 2020 20:00:00 gmt"         header set cache-control "public"     </filesmatch> </ifmodule> # end of leverage browser caching using mod_headers # 

enable apache mod_headers , mod_expires modules

please check mod_expires , mod_headers enable or not on store through below code.

<?php phpinfo();?> 

if both extension not unable server,please follow following steps:-

step 1 :-

now login server using ssh console , continue below steps:

to enable mod_headers:

sudo a2enmod headers 

to enable mod_expires:

sudo a2enmod expires 

step 2 :-

after completing server update, need restart apache server make these changes effective. enter below line in ssh console restart apache.

service apache2 restart 

or else reboot server following code in ssh:

reboot 

use following code in .htaccess file.

<ifmodule mod_headers.c>      # year      <filesmatch "\.(ico|gif|jpg|jpeg|png|flv|pdf)$">           header set cache-control "max-age=29030400"      </filesmatch>      # week      <filesmatch "\.(js|css|swf|woff)$">          header set cache-control "max-age=604800"      </filesmatch>      # 45 min      <filesmatch "\.(html|htm|txt)$">         header set cache-control "max-age=86400"      </filesmatch>       header set connection keep-alive  </ifmodule>  <ifmodule mod_gzip.c>     mod_gzip_on yes     mod_gzip_dechunk yes     mod_gzip_item_include file \.(html?|txt|css|js|php|pl|asp|html)$     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>  <ifmodule mod_deflate.c>     addoutputfilterbytype deflate text/text text/html text/plain text/xml text/css application/x-javascript application/javascript </ifmodule> 

after clear store cache , reload website url,recheck gtmetrix tool or whatever using tool.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -