Stylesheet not updating when I refresh my site
Asked Answered
S

17

80

I am creating a website, but when I made changes to the stylesheet on my site, and I refreshed the site, none of the changes were there.

I tried to use the view source tool to check the stylesheet.css and it isn’t updated either. But when I go to the root of my system it is.

I have to wait at least 20 minutes before I see the update on my site, can anyone tell me why I don’t see changes right away? Is something wrong with my browser, computer, or server?

I also tried deleting my cookies, cache, and history but it still didn’t work.

Surveyor answered 3/10, 2012 at 22:50 Comment(0)
C
224

If your site is not live yet, and you just want to update the stylesheet at your pleased intervals, then use this: Ctrl + F5.

On Mac OS (in Chrome) use: Cmd + Shift + R.

This will force your browser to reload and refresh all the resources related to the website's page.

So every time you change something in your stylesheet and you wanna view the new results, use this.

Chaffinch answered 4/10, 2012 at 0:0 Comment(1)
Holding down the Shift Key while hitting the Refresh Button forces the browser to download all the server files; clearing cache and updating with any newer versions. SHIFT/REFRESH works for both on Mac/PC.... Any operating system, Any browser.Conferee
U
61

Most probably the file is just being cached by the server. You could either disable cache (but remember to enable it when the site goes live), or modify href of your link tag, so the server will not load it from cache.

If your page is created dynamically by some language like php, you could add some variable at the end of the href value, like:

<link rel="stylesheet" type="text/css" href="css/yourStyles.css?<?php echo time(); ?>" />

That will add the current timestamp on the end of a file path, so it will always be unique and never loaded from cache.

If your page is static, you have to manage those variables yourself, so use something like:

<link rel="stylesheet" type="text/css" href="css/yourStyles.css?version=1" />

after doing some changes in the file content, change version=1 to version=2 and so on.

If you wish to disable the cache from caching css files, refer to your server type documentation (it's done differently on apache, IIS, nginx etc.) or ask/search for a question on https://serverfault.com/

Assuming IIS - adding the key under <system.webServer> with the right settings in the root or the relevant folder does the trick.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <caching enabled="false" enableKernelCache="false" /> <!-- This one -->
    </system.webServer>
</configuration>

That said sometimes one still has to recycle the Application Pool to "bump" the CSS. Therefore: Disabling IIS caching alone is not a 100% guaranteed solution.

For the browser: There are some notes on fine-grain controlling the local cache on FF over on SuperUser for the interested.

Unamuno answered 3/10, 2012 at 23:41 Comment(3)
Cached by client not server.Micronutrient
You saved my day, thanks ! It also work for javascript scripts.Rizas
I am using ASP Classic on my site, so adding the following ?<%=time()%> did the trick. Thank you very much.Woodworker
G
17

Easiest way to see if the file is being cached is to append a query string to the <link /> element so that the browser will re-load it.

To do this you can change your stylesheet reference to something like

<link rel="stylesheet" type="text/css" href="/css/stylesheet.css?v=1" />

Note the v=1 part. You can update this each time you make a new version to see if it is indeed being cached.

Gennygeno answered 3/10, 2012 at 22:54 Comment(1)
To add something here, rather than changing the number v=1 everytime, set v = Math.random() So, every time it will generate a new number.Fere
O
2

This may not have been the OP's problem, but I had the same problem and solved it by flushing then disabling Supercache on my cpanel. Perhaps some other newbies like myself won't know that many hosting providers cache CSS and some other static files, and these cached old versions of CSS files will persist in the cloud for hours after you edit the file on your server. If your site serves up old versions of CSS files after you edit them, and you're certain you've cleared your browser cache, and you don't know whether your host is caching stuff, check that first before you try any other more complicated suggestions.

Octant answered 27/6, 2015 at 4:58 Comment(1)
Good info. cpanel is being assumed though. There is no mention of cpanel in the question or tagsOblast
G
2

I had a similar problem, made all the more infuriating by simply being very SLOW to update. I couldn't get my changes to take effect while working on the site to save my life (trying all manner of clearing my browser cache and cookies), but if I came back to the site later in the day or opened another browser, there they were.

I also solved the problem by disabling the Supercacher software at my host's cpanel (Siteground). You can also use the "flush" button for individual directories to test if that's it before disabling.

Gi answered 3/6, 2016 at 17:27 Comment(0)
O
1

In my case, since I could not append a cache busting timestamp to the css url it turned out that I had to manually refresh the application pool in IIS 7.5.7600.

Every other avenue was pursued, right down to disabling the caching entirely for the site and also for the local browser (like ENTIRELY disabled for both), still didn't do the trick. Also "restarting" the website did nothing.

Same position as me? [Site Name] > "Application Pool" > "Recycle" is your last resort...

Oblast answered 22/6, 2017 at 15:35 Comment(0)
H
1

If it is cached on the server, there is nothing you can do in the browser to fix this. You have to wait for the server to reload the file. You can't even delete the file and re-upload it. This could take even longer if you are using a caching server like Cloudflare (it will even survive a server reboot). You could rename it and load a copy.

Headrail answered 13/3, 2019 at 18:34 Comment(1)
I guess this might be a better option to check cached contents on CloudFlare or CDNs.Condemn
D
1

i had the same problem, I use 000webhost to host my site and i also use cloudflare. I'd already disabled all my cache setting from my browser then tried to change some css and reload the page with hard refresh
(shift + click refresh button, ctrl + f5, etc) nothing had changed.

It turns out the issue was coming from cloudflare cache. If you are using cloudflare, you can enable development mode in cloudflare it will temporarily bypass your cache allowing you to see changes to your origin server in realtime.

For someone who still encounter this problem, i hope this can help you

Dispersal answered 30/9, 2021 at 19:17 Comment(0)
S
0

This may be a result of your server config, some hosting providers enable "Varnish" on your domain. This caching HTTP reverse proxy, is used to speed up delivery. One could try to disable varnish on the cpanel (assuming that you have one) and check if it was that.

Secondhand answered 24/1, 2017 at 9:51 Comment(0)
S
0

For reference, I'm developing on a Windows 11 machine ,first run below 2 command

$env:NODE_ENV="development"

$env:TAILWIND_MODE="watch"

now run your application

for reference follow : https://github.com/tailwindlabs/tailwindcss/issues/4081

Sabrasabre answered 11/1, 2022 at 5:28 Comment(0)
P
0

Same problem happened with me I am cleared my browser cash and cookies then automatically running properly

Purism answered 2/9, 2022 at 19:0 Comment(1)
Several existing answers mention that already. Please make your posts additional contribution more obvious. Otherwise this is perceived as "Thanks" for those other ansers. That in turn means your post is not an answer and should be deleted.Shiah
C
0

In Windows: ctrl + shift + R. This will reload and refresh all the files related to the website's page. This works on Windows 11. I tried this in Microsoft Edge.

Coelho answered 8/5 at 10:16 Comment(0)
O
-1

![Clear Cache] Ctrl+Shift+Delete https://i.sstatic.net/QpqhJ.jpg Sometimes it’s necessary to do a hard refresh to see the updates take effect. But it’s unlikely that average web users know what a hard refresh is, nor can you expect them to keep refreshing the page until things straighten out. Here’s one way to do it:<link rel="stylesheet" href="style.css?v=1.1">

Onlybegotten answered 26/1, 2015 at 16:23 Comment(0)
C
-1

I ran into this problem too, a lot of people seem to recommend force reloading your page, which won't fix the issue in cases such as if you're running it on a server. I believe the optimal solution in this scenario is to timestamp your css.

  1. This is how I do it in my Django template:

<link rel="stylesheet" href="{% static 'home/radioStyles.css' %}?{% now 'U' %}" type="text/css"/>

Where adding ?{% now 'U' %} to the end of your css file would fix this issue.

Where ?Wednesday 2nd February 2020 12PM (current date) seems to fix the issue, I also noticed just putting the time fixes it too.

Coffeng answered 12/2, 2020 at 17:7 Comment(2)
Adding a variable to your CSS file path is recommended by two existing answers already.Attentive
@Attentive Sure but information was added with the Jinja templating example.Coffeng
B
-1

First, try to Force reload or Clear cache and Empty chase and hard reload. You can do it by pressing F12 and then by right-clicking on it.

2nd Solution: Check your HTML base tag. You can learn more about it from here.

Burkhart answered 8/2, 2021 at 6:40 Comment(0)
R
-2

I had same issue. One of the reasons was, my application was cached and I was performing local build.

I would prefer deleting the css file and re-adding it again with changes if none of the above comments work.

Rifkin answered 12/11, 2019 at 11:3 Comment(0)
P
-4

Don't update the styles in style.css, instead create a new stylesheet of your own and import in style.css

your-own-style.css
      .body{
           /*any updates*/
       }

import your-own-style.css in style.css

@import url("your-own-style.css");
Pericarp answered 3/2, 2015 at 8:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.