Force browser to clear cache

后端 未结 17 2325
夕颜
夕颜 2020-11-22 05:04

Is there a way I can put some code on my page so when someone visits a site, it clears the browser cache, so they can view the changes?

Languages used: ASP.NET, VB.N

17条回答
  •  轮回少年
    2020-11-22 05:55

    If this is about .css and .js changes, one way is to to "cache busting" is by appending something like "_versionNo" to the file name for each release. For example:

    script_1.0.css // This is the URL for release 1.0
    script_1.1.css // This is the URL for release 1.1
    script_1.2.css // etc.
    

    Or alternatively do it after the file name:

    script.css?v=1.0 // This is the URL for release 1.0
    script.css?v=1.1 // This is the URL for release 1.1
    script.css?v=1.2 // etc.
    

    You can check out this link to see how it could work.

提交回复
热议问题