Browser refreshes html file twice when using Visual Studio Code with Live Server or Browser-Sync

时间:2018-11-13 07:47:49

标签: visual-studio-code

For testing purposes, I have a simple html file that contains two lines of Javascript. I'm using Visual Studio Code (version 1.29.0) with the Live Server extension (version 5.1.1). With the html file loaded in the browser via Live Server, whenever the html file is saved, the browser refreshes (producing a random number in the console). After roughly 1 second, the browser will refresh again (producing a different random number in the console). It does this every time I save the file. The same issue occurs when I try it using Browser-Sync.

I've tried this with Chrome, Firefox, Opera and Edge. They all exhibit the same behavior.

I've been using Visual Studio Code for several months and this wasn't happening until recently that I can remember. I've toggled all of the settings in VSCode that I think might be relevant to the problem, but can't seem to find the issue.

Any ideas as to what is making the browsers refresh twice?

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Javascript Sandbox</title>
</head>
<script>
  var a = Math.floor(Math.random() * 10);
  console.log(a);
</script>
<body>
  <h1>Javascript Sandbox</h1>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

我知道了。我使用Windows10。问题与OneDrive有关。我的html文件存储在OneDrive文件夹中的一个文件夹中。我将该文件夹设置为“始终保留在此设备上”,这意味着它存储为本地副本。但是,当我将文件复制到桌面上并从那里运行时,浏览器仅刷新一次。