-1

I have a website. When I Change something to the style sheet the effect does't fall into user's browser.Then when they clear their cache that new style sheet reflects to then.So my is there any better way to reflect that change whenever I update my code ??

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 1
    This could help you https://stackoverflow.com/questions/1922910/force-browser-to-clear-cache – dantheman Sep 30 '20 at 10:57
  • 1
    set the cache-control header for your stylesheets to like 5 mins: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control – swift-lynx Sep 30 '20 at 11:12
  • What coding language do you use? If you use PHP, you can add a version number to the CSS file based on the modified date `filemtime()` for example. – disinfor Oct 01 '20 at 13:21

1 Answers1

0

My go-to solution would be to set the Cache-Control header's max-age to something like 5 mins. That way users navigating on your page don't have to load the stylesheet each time, but when they come back like an hour later, it is reloaded.

Another way would be to increment a version number as a get parameter on the end of your stylesheet url each time you make changes to the stylesheet:

<link href="/styles/home.css?version=1" rel="stylesheet">

When you increment the version number, the browser thinks it's a different resource and reloads it.

swift-lynx
  • 3,219
  • 3
  • 26
  • 45