Force browser to reload index.htm

前端 未结 3 1328
面向向阳花
面向向阳花 2021-01-30 08:55

how can I force a browser to always load the newest version of index.htm when the page is loaded by entering the URL www.mydomain.com/index.htm or just www.mydomain.com in the b

相关标签:
3条回答
  • 2021-01-30 09:24

    You can use the code below to refresh or reload the currently loaded index page from a URL address entered directly into the browser's address bar, after a specific number of seconds, thereby forcing the browser to always reload the current document. In this case, the number of seconds has been set to 5:

    <meta http-equiv="refresh" content="5" />
    

    Please note that setting the number of seconds to 0 will cause the page to be automatically reloaded instantly, every time it is successfully downloaded.

    0 讨论(0)
  • 2021-01-30 09:37

    To do this, you will need to perform some server-side coding along the way. You can use technologies like PHP or ASP.NET for this. I prefer coding with PHP, so here is a PHP-based example. First of all, make sure your INDEX is called "index.php", rather than "index.html" or "index.htm". Now take note of the following codes and make integrate this to your index.php file, while inserting your own page contents as well:

    <html>
    
        <?php
            header("Content-Type: text/event-stream");
            header("Cache-Control: no-cache");
        ?>
    
        <head>
            <script>
                var sse = new EventSource("index.php");
                sse.onmessage = function(event) {
                    document.write(event.data);
                }
            </script>
        </head>
    
        <body>
    
            <!-- Insert HTML Codes -->
    
            <?php
                flush();
            ?>
    
        </body>
    
    </html>
    
    0 讨论(0)
  • 2021-01-30 09:51

    OK, apparently no-cache was not enough. The following does the trick:

      <meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" />
      <meta http-equiv="cache-control" content="max-age=0" />
      <meta http-equiv="expires" content="0" />
      <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
      <meta http-equiv="pragma" content="no-cache" />
    
    0 讨论(0)
提交回复
热议问题