-1

I have this in my htaccess file:

<IfModule mod_expires.c>
<FilesMatch "\.(gif|png|jpg|jpeg|svg|webp|css|swf|ico|eot|woff|js)$">
  ExpiresActive On
  ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>

Header set Cache-Control "max-age=31536000, public"

I have this in my php file:

if(session_id()=='') session_start();
session_write_close();
header('Cache-Control:max-age=2592000'); 

And yet, when I test the page on cache-checker.com, I get this response:

Server: Apache
X-Powered-By: PHP/7.4.33
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-Frame-Options: DENY
Set-Cookie: PHPSESSID=5f662c687f5b5e3459a01c0a896ec11f; path=/
Referrer-Policy: strict-origin-when-cross-origin
Upgrade: h2
Connection: keep-alive
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
Strict-Transport-Security: max-age=631138519; includeSubDomains
X-XSS-Protection: 1; mode=block
Content-Type: text/html; charset=utf-8

I am trying to enable browser caching.

Any help would be appreciated.

4
  • You can NOT control the browser. The browser decides what to cache. You just can tell, that you would like to expire a resource. Commented Sep 9, 2024 at 19:05
  • 1
    I would go with a curl of your site first, to see what headers are really there: curl -v -I https://example..com. Then you should check your complete webserver chain. Maybe a caching module is enabled. Commented Sep 9, 2024 at 20:26
  • @MarkusZeller But Expires: Thu, 19 Nov 1981 08:52:00 GMT means you aren't even telling 😀 Commented Sep 11, 2024 at 6:34
  • @ÁlvaroGonzález Back to future 🤣 Commented Sep 11, 2024 at 7:18

1 Answer 1

1

Wow. It took a lot of extra searching, but in the end, I found the solution. Add this line:

session_cache_limiter('public');

Before:

session_start();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.