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 (using RAD WEB HOSTING cPanel hosting, this is located at /home/username/public_html).

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"

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 Includes Editor (enables browser caching on a server-wide basis).
  • apache, htaccess, website administration, cache
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

 Remove Login History on Server

On the Linux systems there are three standard commands that show the information about last...

 Recursive Find and Replace Command Line Method

Reference this guide for help with mass find and replace file manipulation in Linux servers.Find...

 How to Bind Additional IPs to Network Interface Card - CentOS

This article explains the process of binding multiple IP addresses to the Network Interface Card...

 How to Change Root Password Using SSH

This article explains the method of changing the root password on a Linux Server using SSH. SSH...

 Disable Network Manager on CentOS 6

This article will provide the steps to disable Network Manager in CentOS 6. Network Manager is...