How to Enable Browser Caching in cPanel?


Browser caching instructs visitors' browsers to store static files (images, CSS, JS) locally, so they don't need to download them again on subsequent visits. This dramatically reduces load time for returning visitors and improves your Google PageSpeed score.

Enable Browser Caching via .htaccess

  1. Login to cPanel → File Manager.
  2. Navigate to public_html.
  3. Open .htaccess (enable Show Hidden Files if not visible).
  4. Add the following code:
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType application/x-javascript "access plus 1 month"
  ExpiresByType text/html "access plus 1 day"
  ExpiresByType application/xhtml+xml "access plus 1 day"
</IfModule>

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

Tip: WordPress users should use a caching plugin like WP Super Cache or W3 Total Cache which handles browser caching automatically alongside page and object caching.

Testing Cache Headers

After enabling, test your site at Google PageSpeed Insights or GTmetrix to confirm the "Leverage browser caching" warning is resolved.

If you continue to face issues, please open a create a request.

這篇文章有幫助嗎? 0 用戶發現這個有用 (0 投票)