we create awesome websites

Leverage browser caching is a cache mechanism for page speed. Most of the static files that are used on web pages can be saved on the computer of your visitor for future access. Every time a visitor accesses a page on your website these files will then be accessed from the visitor’s computer instead of your website, which will significantly speed up page load times.

Fetching resources over the network is both slow and expensive: the download may require multiple roundtrips between the client and server, which delays processing and may block rendering of page content.

Google recommends a minimum cache time of one week and preferably up to one year for static assets, or assets that change infrequently.

We prefer using the first code to enable leverage browser caching!

You can enable leverage browser caching for Apache or NGINX add one of the codes hereunder to the .htaccess file:

#EXPIRE CACHING - LEVERAGE BROWSER CACHING #
ExpiresActive On
ExpiresByType text/html "access 1 hour"
ExpiresByType text/css "access 14 days"
ExpiresByType text/x-javascript "access 3 weeks"
ExpiresByType image/gif "access 2 months"
ExpiresByType image/png "access 2 months"
ExpiresByType image/jpg "access 2 months"
ExpiresByType image/jpeg "access 2 months"
ExpiresByType image/gif "access 2 months"
ExpiresByType application/pdf "access 1 year"
ExpiresByType application/x-shockwave-flash "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
# END EXPIRE CACHING #

Second option

If the above code doesn’t works try this one:

#EXPIRE CACHING - LEVERAGE BROWSER CACHING #
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
# END EXPIRE CACHING #

Note: you can add or remove certain file types from the above examples if you don’t or do want to use it.

If you enable leverage browser caching the next step is: gzip compression

Check this article on what to add to your .htaccess file to compress or deflate your web page on the server before it is delivered to the visitors browser which will decompress it and save up to 90% time: Enable gzip compression using the .htaccess file for Apache