CSS is not being applied after changes

后端 未结 5 769
悲&欢浪女
悲&欢浪女 2020-12-23 20:39

I have problem where I can\'t apply the style in CSS in my ASP.NET MVC application. The behavior is it applies for the first time and then the subsequent changes to the CSS

相关标签:
5条回答
  • 2020-12-23 21:18

    The browser can cache static files such as CSS files.

    If you update a CSS file and the change does not appear when you browse, try using CTRL-F5 within your browser.

    0 讨论(0)
  • 2020-12-23 21:19

    Hit the Ctrl-F5 for reloading the page without using the cached contents

    0 讨论(0)
  • 2020-12-23 21:22

    This will work when anything else won't, like in my case:

    Credit goes to: atticae

    You can append a random query parameter to the stylesheet url (for example via javascript or server side code). It will not change the css file that is being loaded, but it will prevent caching, because the browser detects a different url and will not load the cached stylesheet.

    <link rel="stylesheet" type="text/css" href="http://mysite/style.css?id=1234">
    
    0 讨论(0)
  • 2020-12-23 21:22

    Unfortunately ctrl+f5 does not work for me. I have to go to Chrome: F12 -> Network tab -> right click within white area where all the get and post records are -> Clear browser cache. Now if you press ctrl + f5 or just f5 it should work.

    0 讨论(0)
  • 2020-12-23 21:27

    In my case the problem was I had a resource style file which was referring by the code

    string location = Page.ClientScript.GetWebResourceUrl(typeof(PageBase), "MyNS.Common.Web.Base.CommonStyle.css");
    LiteralControl include = new LiteralControl(string.Format(tempLink, location));
    

    When I change / add some style in the file it was not reflecting in the CommonStyle.css it was not reflecting in the web page even after clearing the cache(ctrl + f5 , ctrl + shift + f5)?

    On my analysis I found the reason was -

    stop the debugging, rebuild the solution and run it again so that all the web resource styles load once again, simply clearing the cache as we does normally for any html change will not help,after doing this my change in the style got reflected in the web page and it fixed my problem.

    0 讨论(0)
提交回复
热议问题