When I make any changes to my CSS file, the changes are not reflected in the browser. How can I fix this?
- 2I am faced with the same problem. The only way I found to fix this was to rename the file. No matter what I tried, Firefox kept reloading the old file. Only after a rename did I see the correct css.AntonioCS– AntonioCS2013-10-03 11:58:05 +00:00Commented Oct 3, 2013 at 11:58
- 3Another quick way i found that works when I test thing is open the developer console and then go to the settings and click the check box "Disable cache (while DevTools is open)" - then i can test code with the console and know that I always see the recent changesTrojanMorse– TrojanMorse2015-10-23 17:49:00 +00:00Commented Oct 23, 2015 at 17:49
15 Answers
The fix is called "hard refresh" http://en.wikipedia.org/wiki/Wikipedia:Bypass_your_cache
In most Windows and Linux browsers: Hold down Ctrl and press F5.
In Apple Safari: Hold down ⇧ Shift and click the Reload toolbar button.
In Chrome and Firefox for Mac: Hold down both ⌘ Cmd+⇧ Shift and press R.
Comments
Try opening the style sheet itself (by entering its address into the browser's address bar) and pressing F5. If it still doesn't refresh, your problem lies elsewhere.
If you update a style sheet and want to make sure it gets refreshed in every visitor's cache, a very popular method to do that is to add a version number as a GET parameter. That way, the style sheet gets refreshed when necessary, but not more often than that.
<link rel="stylesheet" type="text/css" href="styles.css?version=51"> 3 Comments
A good way to force your CSS to reload is to:
<link href='styles.css?version=1' rel='stylesheet'></link> And then just increment the version number as you change your CSS. The browser will then obey. I believe Stack Overflow uses this technique.
1 Comment
I always use Ctrl+Shift+F5 out of habit, it should force a full-refresh including by-passing any http proxies you may be going through.
1 Comment
I had this issue. Turns out I completely forgot I had CloudFlare setup on the domain I was live testing on.
CloudFlare caches your JavaScript and CSS. Turned on development mode and BAM!
2 Comments
The Ctrl + F5 solution didn't work for me in Chrome.
But I found a different solution that did work from here: How to Clear Chrome Cache for Specific Website Only (3 Steps):
- As the page is loaded, open Chrome Developer Tools (Right-Click > Inspect) or (Menu > More Tools > Developer Tools)
- Next, go to the Refresh button in Chrome browser, and Right-Click the Refresh button.
- Select "Empty Cache and Hard Refresh".
Comments
Having this problem before I found out my own lazy solution (based on other people suggestions). It should be helpful if your <head> contents go through php interpreter.
To force downloading file every time you make changes to it, you could add file byte size of this file after question mark sign at the end.
<link rel="stylesheet" type="text/css" href="styles.css?<?=filesize('styles.css');?>"> EDIT: As suggested in comments, filemtime() is actually a better solution as long as your files have properly updated modify time (I, myself, have experienced such issues in the past, while working with remote files):
<link rel="stylesheet" type="text/css" href="styles.css?<?=filemtime('styles.css');?>"> Since I found this thread having the same problem, 10 YEARS later, I'll add my own solution too. I use PHP most of the time, and rather than requiring the user to press unusual buttons to refresh the page, or myself to remember to bump a version number embedded in a link, I used the filemtime() function to get the modification time of the css file (as a unix timestamp), and then use THAT number as the parameter.
$FILE_TIME = filemtime("main.css"); $CSS_LINK = "main.css?version=$FILE_TIME"; While results in a URL like:
http://example.com/blah/main.css?version=1602937140 This entirely disables caching, since every time the page is refreshed, it will believe it needs to grab the CSS file again, changed or not... but that's far less frustrating than forgetting to manually update this trick and wasting time wondering why it isn't right. You can always remove it from a production server.
If you are using plain HTML, you could probably engineer a javascript wrapper or some such, but that's probably more trouble than it's worth.
Comments
The reason this occurs is because the file is stored in the "cache" of the browser – so there is no need for the browser to request the sheet again. This occurs for most files that your HTML links to – whether they're CDNs or on your server, for example, a stylesheet. A hard refresh will reload the page and send new GET requests to the server (and to external b if needed).
You can also empty the caches in most browsers with the following keyboard shortcuts.
Safari: Cmd+Alt+e
Chrome and Edge: Shift+Cmd+Delete (Mac) and Ctrl+Shift+Del (Windows)
