0

I made a simple website in PHP. How do I make sure that after making changes to the files on the server (for example css files) the users visiting the site will see it exactly the way it was edited to look? At the moment when i change css files the user has to clear the site's data (hard refresh) and only then the changes are visible.

I tried changing the names of css files every time I edit them so that the browser has to load the file and not use an existing one in cache, but that only seems to work on desktop. Mobile device browsers for some reason do not load the new file - instead they act as if there is no css file at all.

I also tried this: How to clear browser cache with php? But to no effect.

Sorry if I didn't provide enough information or sth, I'm new here. Please guide me :)

  • Sending header is the right way to set how long browser should serve your page from cache. On mobile seems that browser is serving old cached html files, which contains path to old CSS files which don't exist any more, so they are not loaded. What you can do is set shorted caching interval, but you can't force browser to load your new page since communication is going one way, browser to server. – MilanG Aug 17 '23 at 08:36
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 19 '23 at 16:54

1 Answers1

0

You should check each type of request—CSS, JS, and HTML—using the Network tab. You'll need to locate the Cache-Control and Expires directives in the Headers section, which might look like the following:

Cache-Control: public, s-maxage=315, max-age=60
Expires: Tue, 13 Aug 2024 08:03:23 GMT

Larger values will result in cached content being stored for a longer time, potentially without providing a fresh result. These values can be configured on your server or for each endpoint through headers.

It's also important to know whether your site employs a CDN, although cache values can always be customized for individual endpoints.

I hope this information proves useful as you continue your investigations.

Teo
  • 11
  • 2