search

Home  >  Q&A  >  body text

A forced way to clear browser cache

<p>Is there a way I can put some code on my page so that when someone visits the site, it clears the browser cache so they can see the changes? </p> <p>Languages ​​used: ASP.NET, VB.NET, and of course HTML, CSS and jQuery. </p>
P粉727531237P粉727531237539 days ago589

reply all(2)I'll reply

  • P粉253518620

    P粉2535186202023-08-14 11:40:18

    See the cache-control and expires META tags.

    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <META HTTP-EQUIV="EXPIRES" CONTENT="Mon , 22 Jul 2002 11:12:01 GMT">

    Another common practice is to append a changing string to the end of the requested file. For example:

    <script type="text/javascript" src="main.js?v=12392823"></script>

    reply
    0
  • P粉587970021

    P粉5879700212023-08-14 00:20:37

    If this is a change regarding .css and .js, one way to do this is by appending something like "_versionNo# to the end of each published filename ##" content to perform "cache destruction". For example:

    script_1.0.css // 这是发布 1.0 的 URL
    script_1.1.css // 这是发布 1.1 的 URL
    script_1.2.css // 等等
    

    or after the file name:

    script.css?v=1.0 // 这是发布 1.0 的 URL
    script.css?v=1.1 // 这是发布 1.1 的 URL
    script.css?v=1.2 // 等等
    

    You can check out this

    link to see how it works.

    reply
    0
  • Cancelreply