How to prevent CSS caching on a web page?

后端 未结 9 1841
你的背包
你的背包 2020-12-14 17:42

I am learning to develop xhtml, css web pages. Often I am doing changes in CSS but it do not reflect on page because of browser cacheing and if I manually clear cahceing it

相关标签:
9条回答
  • 2020-12-14 18:09

    You can use random version id in your link. for example use this:

    <link   href=<%="'mystyle.css?version="+ DateTime.Now.ToString("yyyyMMddhhmmss") +"'"%>   rel="stylesheet" type="text/css"/>
    

    where myStyle.css is stylesheet file and DateTime.Now.ToString("yyyyMMddhhmmss") function used for generate random different version id. By using this random version id,browser forced to reload your css.

    0 讨论(0)
  • 2020-12-14 18:10

    instead of writing <link> tag using html just use php code. inside <link> tag at the end use php mt_rand() function which will produce a random number and thus your stylesheet will never get cached. <?php echo "<link rel='stylesheet' type='text/css' href='style.css?'".mt_rand().">"; ?>

    0 讨论(0)
  • 2020-12-14 18:13

    With no catching: Put changeable strings at the end of css path, as bellow:

    <link rel="stylesheet" type="text/css" href="style.css?2016-12-3:10 13 30"/>
    

    Refresh when version changes:

    <link rel="stylesheet" type="text/css" href="style.css?v=1.1.0"/>
    
    0 讨论(0)
提交回复
热议问题