强制浏览器重新加载index.htm

时间:2022-08-23 03:50:33

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.

如何通过在浏览器的地址栏中输入URL www.mydomain.com/index.htm或只需www.mydomain.com并按Enter键,强制浏览器在加载页面时始终加载最新版本的index.htm。

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.

我在Chrome中尝试这个,最新版本的index.htm显然只是加载,当我手动刷新(F5),或者当URL已经在浏览器的地址栏中时,我按下回车键。

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??

我想我正在做一些非常愚蠢的事情,因为当我搜索这个问题时,我能找到的解决方案是关于如何通过将?v = xxxx附加到文件名来使浏览器重新加载.js和.css文件。但是,如果不是最新版本的index.htm页面(我正在进行这些修改),它应该如何工作?

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.

在index.htm的中。但这似乎没有任何影响。

Any help would be greatly appreciated!

任何帮助将不胜感激!

Thanks, Linus

谢谢,Linus

4 个解决方案

#1


33  

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" />

#2


2  

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:

您可以使用以下代码在特定秒数后从直接输入浏览器地址栏的URL地址刷新或重新加载当前加载的索引页,从而强制浏览器始终重新加载当前文档。在这种情况下,秒数已设置为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将导致每次成功下载页面时立即自动重新加载页面。

#3


1  

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:

为此,您需要在此过程中执行一些服务器端编码。您可以使用PHP或ASP.NET等技术。我更喜欢用PHP编码,所以这里是一个基于PHP的例子。首先,确保您的INDEX被称为“index.php”,而不是“index.html”或“index.htm”。现在请注意以下代码并将其集成到index.php文件中,同时插入自己的页面内容:

<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>

#4


0  

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

用Google搜索并在本网站上发布。 maby这有帮助:http://code.tutsplus.com/tutorials/4-ways-to-auto-refresh-your-browser-when-designing-new-sites--net-13299希望有所帮助,807

#1


33  

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" />

#2


2  

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:

您可以使用以下代码在特定秒数后从直接输入浏览器地址栏的URL地址刷新或重新加载当前加载的索引页,从而强制浏览器始终重新加载当前文档。在这种情况下,秒数已设置为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将导致每次成功下载页面时立即自动重新加载页面。

#3


1  

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:

为此,您需要在此过程中执行一些服务器端编码。您可以使用PHP或ASP.NET等技术。我更喜欢用PHP编码,所以这里是一个基于PHP的例子。首先,确保您的INDEX被称为“index.php”,而不是“index.html”或“index.htm”。现在请注意以下代码并将其集成到index.php文件中,同时插入自己的页面内容:

<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>

#4


0  

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

用Google搜索并在本网站上发布。 maby这有帮助:http://code.tutsplus.com/tutorials/4-ways-to-auto-refresh-your-browser-when-designing-new-sites--net-13299希望有所帮助,807