How to Optimize PHP TTFB and Browser Caching on Shared Hosting (Hostinger / cPanel)

Advertisement

Google AdSense In-Article Display Placement

Publisher ID: ca-pub-XXXXXXXXXXXXXXXX (Configured in config.php)

Time to First Byte (TTFB) is a crucial Core Web Vitals metric directly affecting Google rankings. Discover how to reduce TTFB from 1,800ms down to under 200ms on shared hosting using OPcache, mod_deflate, and optimal caching headers.

✔ Rapid Direct Solution

1) In Hostinger hPanel, enable the "opcache" PHP extension (stores precompiled script bytecode in RAM). 2) Add mod_expires browser caching directives in .htaccess for images, CSS, and JS (1 year max-age). 3) Enable Gzip compression with mod_deflate. 4) Use flat-file or Redis object caching.

1. Problem Diagnosis & Symptoms

On shared hosting, compiling PHP files on every request causes high server latency and hurts Google Core Web Vitals.

2. Primary Root Causes

  • Cause: OPcache disabled.
  • Cause: Missing browser cache headers requiring re-downloads of static assets.

3. Step-by-Step Diagnostic Fixes

1

Add Gzip and Browser Caching to .htaccess

Enable compression and caching headers:

APACHECONF
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
</IfModule>

4. How to Verify the Resolution

  • ✔ Test URL in PageSpeed Insights and verify TTFB is under 200ms.

5. Diagnostic Troubleshooting Matrix

Symptom Observed Root Cause Recommended Action
TTFB remains over 1.5 seconds Database query execution on dynamic pages taking 1+ seconds Profile SQL queries and add indexes on frequently filtered columns

6. Critical Mistakes to Avoid

  • ❌ Caching dynamic pages that output personalized user cookies or CSRF tokens.

7. Frequently Asked Questions

❓ What is a good TTFB according to Google?

Google considers a TTFB under 800ms "Good", with under 200ms being ideal for top SEO rankings.

Official Technical References

Advertisement

Google AdSense In-Article Matched Content Unit