0

I'm working on php/css project through localhost and nearly every time I change css and reload page, css remains unchenged until I delete cookies, cache and other site data (somethimes even then it doesn't work straight away). Css is linked correctly, as well as aeverything else, so this is not a problem with code, but with browser/cache.

My question is- is there a way to resolve this issue other than deleting cookies and cache every time I change something in my css?

Youssouf Oumar
  • 29,373
  • 11
  • 46
  • 65
lordsanken
  • 38
  • 11
  • 1
    Does this answer your question? [Cache busting via params](https://stackoverflow.com/questions/9692665/cache-busting-via-params) – Alon Eitan May 27 '22 at 06:49
  • 1
    just a quick tip: if you reload the page with `ctrl + f5`, the cache is cleared and changes are shown... way faster than any server side settings. – toffler May 27 '22 at 06:59
  • @AlonEitan I tried it several times, but it doesn't change anything :'( – lordsanken May 27 '22 at 07:05
  • @toffler thanks for the tip, I've been using it before and I just switched to ```ctrl+R``` for no reason, but I had no idea that ```ctrl+F5 ``` clears cache. Anyways, it doesn't change anything – lordsanken May 27 '22 at 07:07
  • If this doesn't work, you can add a "changing" param to the include of your css in php... something like `".../file.css?v=".time()"`. If it is still not working, it might be not a caching problem – toffler May 27 '22 at 07:11
  • Does this answer your question? [How to prevent Browser cache for php site](https://stackoverflow.com/questions/13640109/how-to-prevent-browser-cache-for-php-site) – WebPajooh May 27 '22 at 07:18
  • Your browser most likely also have a Developer tools section, which usually contains a setting for disabling client cache. [Here's how you do it in Chrome](https://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development) – M. Eriksson May 27 '22 at 07:59

2 Answers2

3

Please add a query parameter to CSS with dynamic file modified time:

<link rel="stylesheet" href="style.css?v=<?php echo filemtime("style.css");?>" />
0

All the comments and answers were helpful, but none of them solved the problem long term.

After some experimenting, I found an answer: disable saving cookies and cache for given site, in

chrome settings > advanced > Privacy and security > Sites that can never use cookies

lordsanken
  • 38
  • 11