1

As in Magento 1 to increase the page speed score and Y-slow score we have used Leverage Browser Caching for Images, CSS and JS code in .htaccess file but same script in Magento2 is not working.

below is the code of browser cache:

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

Why Magento 2 is not considering this code.?

If anything is wrong in code please share the code so we can optimize the code.

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked Feb 8, 2019 at 9:56
5
  • are you using shared hosting? Commented Feb 8, 2019 at 10:12
  • No,we are using AWS dedicated EC2. Commented Feb 8, 2019 at 10:13
  • you can try this one fishpig.co.uk/magento/optimisation/leverage-browser-caching Commented Feb 8, 2019 at 10:15
  • This is also not working. Commented Feb 8, 2019 at 10:23
  • do you have apache mod_expires? Commented Mar 9, 2020 at 8:41

2 Answers 2

2

I had also faced the similar issue, even after updating .htaccess caching was not applied to files. Enable mode expires module and restart apache2, fixed issue.

sudo a2enmod expires
sudo service apache2 restart
answered Mar 9, 2020 at 7:42
1

Add the following at the following:

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

It will be clear the Leverage browser aching issue.

answered Apr 30, 2019 at 6:31
1
  • The steps you suggest for increasing the Magento 2 speed right? Commented Oct 3, 2020 at 6:47

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.