PHP site not showing cache control. Do not cache anything

INTRO

I have a task to fix an existing site problem that is not cached (except for a browser session). When you close the session and open the browser again, the page loads a lot of images, JS and CSS again. Since I have ~ 60 items each time, there is a big problem with loading.

PROBLEM

Looking at the Chrome console, audits The following resources have no cache expiration ... Audit

And in the network element in the "Response headers" section, the line "cache control" is not even displayed. Mating head

TRIED SOLUTIONS

I installed the information in the .htaccess file and made sure that mod_expires active:

 <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" </IfModule> 

I added the Cache-control meta tag to the html head, which also appears in the page source code, so it compiles.

 <meta http-equiv="Cache-control" content="public" content="max-age=604800"> 

And I would like to add that most likely this is not a server problem, since the host of the production page set it to normal by default. (And I do not have access to this server)
I would be delighted if someone could give me some indications that I was missing or did not check or just did not understand.

Main.css headers added enter image description here

Thanks!

+7
caching apache
source share
2 answers

Well, although it’s stupid (as I expected), but I didn’t read about anything and just forgot about the need for this.

Decision

It turned out that all this had changed (as I said, everything was activated on the server, access files, etc.). And the problem is that I could not clear the cache after changing the caching information . Now, after three days, I started working on some CSS needed to reset the cache and boom - all new headers are active for all elements.

+2
source share

You can set headers via php, as this is a php site.

 <?php header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days) ?> 

You can also use FilesMatch, like this in your .htaccess

 <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=31536000, public" </FilesMatch> 
+2
source share

All Articles