Force browser to reload index.htm

2019-03-09 10:02发布

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 browser's address field and pressing enter.

I'm trying this in Chrome and the newest version of index.htm is apparently only loaded, when I refresh manually (F5), or when the URL is already in the browser's address field and I press enter.

I guess I am doing something extremely stupid, because when I searched for the issue, all I could find were solutions about how to make a browser reload your .js and .css files by appending ?v=xxxx to the file names. But how should this work, if not even the newest version of index.htm page, in which I am doing these modifiactions, is loaded??

I also tried putting

<meta http-equiv="cache-control" content="no-cache">

in the <head> of index.htm. But this does not seem to have any effect.

Any help would be greatly appreciated!

Thanks, Linus

4条回答
我想做一个坏孩纸
2楼-- · 2019-03-09 10:31

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.

查看更多
男人必须洒脱
3楼-- · 2019-03-09 10:35

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" />
查看更多
beautiful°
4楼-- · 2019-03-09 10:51

Googled and came out on this website. maby this helps: http://code.tutsplus.com/tutorials/4-ways-to-auto-refresh-your-browser-when-designing-new-sites--net-13299 Hope that helps, 807

查看更多
神经病院院长
5楼-- · 2019-03-09 10:53

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>
查看更多
登录 后发表回答