HostingDomainsEmailSSLPricingSupport
Login to Client Area Get Started Free
📖 Knowledge Base

How Can We
Help You?

Browse guides, tutorials and troubleshooting articles for all our services.

How to Enable Browser Caching in Apache Using .htaccess

How to Enable Browser Caching in Enhance Apache Using .htaccess

Browser caching helps your website load faster by storing static files (images, CSS, JavaScript) on the visitor’s device. When enabled correctly, returning visitors load your pages much faster and your server handles fewer requests.

This guide explains how to enable caching on an Enhance-managed Apache server using a simple .htaccess file.


Why Enable Caching?

  • Faster page loads for returning visitors
  • Reduced server load because fewer files are re-downloaded
  • Better SEO as Google rewards optimized performance
  • Improved user experience across all devices

Where to Place the .htaccess File

To apply caching, place the file here:

/public_html/.htaccess

If the file does not exist, create it.


Recommended .htaccess Configuration

The following rules enable compression, set caching for static files, and safely cache HTML for a short time.

1. Enable GZIP Compression

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

2. Set Expiration Headers for Static Files

<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 image/x-icon "access plus 1 year"

    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"

    ExpiresByType application/pdf "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"

    ExpiresDefault "access plus 2 days"
</IfModule>

3. Cache HTML Safely (Short Duration)

 A short cache is safest:

<FilesMatch "\.(html|htm)$">
    FileETag None
    <IfModule mod_headers.c>
        Header unset ETag
        Header set Cache-Control "max-age=3600, private, must-revalidate"
    </IfModule>
</FilesMatch>

How to Apply This in Enhance

  1. Log into your Enhance panel.
  2. Open Websites→ File Manager.
  3. Navigate to public_html/.
  4. Create or edit the .htaccess file.
  5. Paste the full configuration above.
  6. Save the file.

How to Verify Caching Is Working

You can test caching using your browser’s developer tools:

  1. Open Chrome DevTools → Network tab.
  2. Reload the page.
  3. Click any CSS, JS, or image file.
  4. Check the Response Headers section.

You should see:

  • Cache-Control with long durations for static files
  • Expires header
  • Content-Encoding: gzip for compression

Important Notes

  • If you update CSS or images, add a version number (e.g., app.css?v=2) so browsers fetch the new file.
  • If you make a mistake in .htaccess, Apache may show a 500 error. Simply remove or correct the file.

Conclusion

By enabling caching through .htaccess, your website becomes significantly faster and more efficient. This improves user experience, reduces server load, and enhances SEO performance.

Can't Find What You're Looking For?

Our support team is available 24/7 to help. Open a ticket and we'll get back to you as soon as possible.