Search code examples
html.htaccesscachingbrowser-cachehttp-caching

browser caching .htaccesss is not working


My code for Leverage browser caching doesn't seem to work i have written the following in the .htaccess but when i ran PageSpeed insights i get the Leverage Browser:

Can somebody kindly advice on what i am doing wrong?

  ## EXPIRES CACHING ##
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType images/dots.gif "access plus 1 month"
    ExpiresByType images/homepage/1.5mw_installed.jpg "access plus 1 month"
    ExpiresByType images/homepage/350kw_optimizers.jpg "access plus 1 month"
    ......
    ExpiresByType stylesheets/responsive.css "access plus 1 month"
    ExpiresByType stylesheets/teal.css "access plus 1 month"
    ExpiresByType stylesheets/style.css "access plus 1 month"
    ExpiresByType stylesheets/websymbols/websymbols-regular-webfont.woff "access plus 1 month"
    </IfModule>
## EXPIRES CACHING ##

Thank you in advance


Solution

  • #==== CACHE FILES FOR 1 WEEK ====
    <IfModule mod_expires.c>
      ExpiresActive On
      <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
        ExpiresDefault "access plus 7 days"
      </FilesMatch>
    </IfModule>
    

    You can change which files you want to cache in the list (remove or add). Change the ExpiresDefault to change how long files are cached for.

    This code is tested and works. Google Page Speed recognises it.