Enable Browser Caching with htaccess File


Enable browser caching to reduce website loading times, by taking advantage of caching of specific file types in the web browser.

For shared hosting, reseller hosting, and any other users that are not on a private server (root level access), the simplest way to do this is by adding text to the .htaccess file in the document root for the website's file directory. 

Using your preferred text editor or cPanel's File Manager, navigate to your website's document root.

Open the .htaccess file and add the following lines of text:

<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 text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>



Save the .htaccess file and the designated file types will now be cached in web browsers to prevent loading on every access. This will speed up the website loading time, while simultaneously reducing the server workload and bandwidth usage.

For alternative methods of enabling browser caching, see Enable Browser Caching with cPanel Include Editor (enables browser caching on a server-wide basis).

  • apache, website administration, cache
  • 1 Benutzer fanden dies hilfreich
War diese Antwort hilfreich?

Related Articles

View Server PHP Environment with phpinfo.php

The phpinfo() function outputs a huge amount of information about the system you're using, such...

How to Create Sudo User on CentOS

This article provides step-by-step setup guide for adding Sudo user to CentOS system. The sudo...

How to Use Sudo

This article provides a guide to using a Sudo user on CentOS server. From the command line,...

Set Server Time Zones with Timedatectl

This article provides a guide to setting the server time and server time zone settings using...

508 Resource Limit is Reached

If your website is on a cPanel hosting account, you may have noticed the following error message:...