2

I added some lines in my .htaccess file, following Is it possible to leverage browser caching?, but Page speed tool still throws "Leverage browser caching error." for only images.

  • Welcome to Drupal Answers! This question is too broad: You say you added some lines, without saying exactly which ones; You say an external tool gives you an error, but not for which files. Plus, you aren't asking any explicit question. Implicit questions don't work well on Stack Exchange. – kiamlaluno May 17 '16 at 6:57
  • Are the urls listed on the report a domain you have control over? – mikeytown2 May 18 '16 at 1:33
  • Just enanling mod_expires on apache will let the default .htaccess mod_expires rules work and give a good result. – GiorgosK Sep 5 '18 at 5:11
5

Read this article about Leverage Browser Caching for Images, CSS and JS.

Add these lines to your .htacess file.

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##

Also you can try

<FilesMatch "\.(jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=604800, public" </FilesMatch>
  • i added these lines in my .htaccess file but its not working. – udhaya kumar UK May 17 '16 at 6:49
  • did you try clear cache? and how do you test it is not work? – Yusef May 17 '16 at 6:52
  • yeah, i cleared all caches. after that i checked performance using google page speed tool.still it showing leverage browser caching proble for lot of png images. – udhaya kumar UK May 17 '16 at 6:55
  • did you try to restart Webserver(apache or nginx)?can you tell your website Url to me? – Yusef May 17 '16 at 6:56
  • 1
    i used below code it works clearly. "<FilesMatch "\.(jpg|jpeg|png|gif|swf)$"> Header set Cache-Control "max-age=604800, public" </FilesMatch>" – udhaya kumar UK May 18 '16 at 8:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.