Leverage Browser Caching

On the Basic Options tab, in the Miscellaneous Settings, there's a button labelled Optimize .htaccess. Clicking this button will add codes to the .htaccess file at the root of your site (on an Apache server) that directs the browser to cache static resources served from the server.

Optimize .htaccess button

Optimize .htaccess button

These codes are added actually when the plugin is installed so most likely you don't have to do anything. However you can click the button to ensure they are installed. You should get either of the following messages:

Codes for 'leverage browser caching' already exist in the .htaccess file.

Tha plugin had already put the codes in the file. Most likely from a previous installation. You can FTP to the file to view and check that the codes are indeed there.

The codes for 'leverage browser caching' were added to the .htaccess file successfully.

The codes were added to the .htaccess file in the root of the site as shown above. Static files should now be cached by the browsers.

The plugin failed to add the 'leverage browser caching' code to the .htaccess file.

For some reason the attempt didn't work. Most likely due to permissions issue and the pluign couldn't write the codes to the file. This would require further exploration and troubleshooting to determine the reason why. For this the recommendation would be to submit a ticket with admin access to the site and FTP login to the server.

An .htaccess file could not be found in the root folder of this site.

You do not have an .htaccess file at the root of your site. You will need to manually add one or perhaps there's one there but has the '.txt' extension appended to it rendering it as a text file. Rename the file to .htaccess so it can be used and configured.

The codes in the .htaccess file will look like the ones shown below. Please note that these codes will be removed on uninstallation of the plugin as part of the clean up procedure.

Codes in .htaccess file for browser caching. 

<IfModule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault "access plus 1 month"

# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest "access plus 0 seconds"

# Your document html
  ExpiresByType text/html "access plus 0 seconds"

# Data
  ExpiresByType text/xml "access plus 0 seconds"
  ExpiresByType application/xml "access plus 0 seconds"
  ExpiresByType application/json "access plus 0 seconds"

# Feed
  ExpiresByType application/rss+xml "access plus 1 hour"
  ExpiresByType application/atom+xml "access plus 1 hour"

# Favicon (cannot be renamed)
  ExpiresByType image/x-icon "access plus 1 week"

# Media: images, video, audio
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/jpg "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType video/ogg "access plus 1 month"
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"

# HTC files (css3pie)
  ExpiresByType text/x-component "access plus 1 month"

# Webfonts
  ExpiresByType application/x-font-ttf "access plus 1 month"
  ExpiresByType font/opentype "access plus 1 month"
  ExpiresByType application/x-font-woff "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# CSS and JavaScript
  #ExpiresByType text/css "access plus 1 year"
  #ExpiresByType application/javascript "access plus 1 year"

  <IfModule mod_headers.c>
    Header append Cache-Control "public"
  </IfModule>

</IfModule>
						

I'm still seeing this error after updating .htacces.  If you're seeing this error on your gtmetrix.com or PageSpeed report after adding these codes then check the details to view the actual files that are triggering this rule. If the files are from your server then you need to check with your host to verify if the mod_expires module is installed and enabled. This now becomes a server issue and we are not able to provide support on this.

Dynamically loaded external files.  If the files are from external servers, then most likely these files were loaded dynamically using javascript. This means the links to the files are not embedded in the HTML source of the page so the plugin cannot access them to optimize them. You can check the HTML source of the page for the links of these files to verify. If they're not there but the analytic report shows they're being loaded, then they were loaded dynamically

Since these files are served from external servers then the codes in your .htaccess file or your server's configuration have no effect on them. Unfortunately there's nothing more the plugin can do to address this. Notable examples are Google Analytic files, Google Maps files, and files from social media application. You must now determine if you need to load these applications on your landing pages to further optimize your site.