PHP and caching breaks site

Website URL

Error Message

I decided to add a basic login system to my site, just to test - and now my site crashes intermittently when I reload it with a forced cache reset. I have already tried disabling and enabling caching on the server and browser side - it didn’t help:

<IfModule mod_headers.c>
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0

I also tried cache boosting CSS styles with:

<link rel="stylesheet" href="css/style.css?<?php echo substr(str_shuffle(md5(time())), 0, 10); ?>">

…but this made it even worse, and the site generally broke down completely much more often. Also, I tried enabling and disabling the PHP interpretation handler inside .html files via .htaccess:

AddType application/x-httpd-php .html
<FilesMatch "\.html$">
SetHandler application/x-httpd-php

…and just changing the extension from html to PHP. However, this did not give results - everything remained exactly the same as it was.
This problem can be easily noticed if you go for example, in incognito mode (InPrivate) and refresh the page with a cache reset, or if, for example, the index.html or main.css file changes on the cached site. This will break all styles, and everything will be fixed only after 20 - 40 minutes, or even never at all.

This is how my website looks with “killed” styles:

And now how it SHOULD look like (ss from localhosted site on openserver):

Other Information

I already re-checked all of my code (include php) and it have no problems. Also i asked GPT-4 but it said that my code don’t have any errors (well, it’s ineffective, but it shouldn’t completly break my site).
Here’s my .htaccess file:

Options All -ExecCGI -Indexes -Includes +FollowSymLinks
#<FilesMatch "\.(css|js)$">
#Header set Cache-Control "max-age=0, public"
<IfModule mod_headers.c>
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
# Remove ?i=1
RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^([^.]+)$ $1.html [NC,L]
RewriteCond %{THE_REQUEST} /index\.(html|php|htm)\s [NC]
RewriteRule ^(.*?)index\.(html|php|htm)$ /$1 [L,R=301,NC]

AddType application/x-httpd-php .html
<FilesMatch "\.html$">
SetHandler application/x-httpd-php

ErrorDocument 403
ErrorDocument 404
ErrorDocument 405
ErrorDocument 406
ErrorDocument 500

I did that, and I did not experience this issue.

Try looking what’s going wrong in your Developer Tools (specifically the Console should output some warnings), however be advised that you may need to disable the current script you have that forces a debugger state.

1 Like

Well, i have some “network fetch errors” from the dev console (Firefox):

But it seems that those .js-scripts are still loading. Actually, i have no clue why did you not experienced that… I think that’s a bit random, maybe. But my friends still gets those crashes (ss from VK dm’s)


1 Like

Without being able to see why the requests to the CSS etc. fail, I have no idea how it could be fixed. Having the errors from the browser’s developer tools (either Console or Network) would tell us a lot more.

The only time I got technical advice from ChatGPT, the answers were completely wrong. Like using options and functions that just don’t exist. ChatGPT is good for a basic primer, but after that, nothing beats Google and StackOverflow for finding code snippets that do what you want to do.

Using ChatGPT is ineffective in my opinion. The “code” it produces can definitely break your site.


I wasn’t asking ChatGPT, which is GPT-3.5. I was asking GPT-4, which is more effective with code uploaded on the pastebin, but that’s not the point.

I don’t have such problems on my local website (OpenServer), even when the site is open to the entire internet via my IP address. However, this issue seems to be occurring randomly at the moment. Based on the debug information, it appears that the browser is somehow accessing and loading old copies of .css and .js files. I have tested this with my friend and noticed that his and mine browser somehow were randomly accessing old copies of files such as main.js and style.css, even after the cache was fully purged. I don’t wanna appear foolish, but I am struggling to understand why this is happening.
It’s not even obfuscated rn, and don’t have any debbuger detections in it:

The actual code:

You use Cloudflare and probably it keeps certain files in the cache until they expire (depending on their value)
before you forced that there is no cache

hint - purge all cache in CF, then force your/a friend’s browser to refresh everything and then test


Yeah, it seems that after purging all cache in CloudFlare, the site began to work just fine. I can’t even believe it, but, however, I am very grateful to you for your help, albeit seemingly insignificant.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.