Simple configuration of Apache website caching using .htaccess

Simple configuration of Apache website caching using .htaccess

Caching is a primary and cost-effective method to enhance a website’s performance.

To enable caching on a website running Apache, locate (or create) the .htaccess file and insert the appropriate code:

<IfModule mod_headers.c>
	<FilesMatch "\.(css|js|ttf|jpg|jpeg|png|webp)$">
		Header set Cache-Control "max-age=172800, public"
	</FilesMatch>
</IfModule>

You can include additional file extensions in the cache during page load by appending them to the FilesMatch function argument.

The max-age parameter determines the storage duration of cached files, measured in seconds. A value of 172800 equates to a period of two days.