visual-studio-code - Browser refreshes html file twice when using Visual Studio Code with Live Server or Browser-Sync
问题描述
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>
解决方案
我想到了。我使用的是 Windows 10。问题与 OneDrive 有关。我的 html 文件存储在我的 OneDrive 文件夹中的一个文件夹中。我将该文件夹设置为“始终保留在此设备上”,这意味着它存储为本地副本。但是,当我将文件复制到桌面并从那里运行时,浏览器只会刷新一次。
推荐阅读
- java - 在java中从一种类型转换为另一种类型的简单方法(当字段相似时)?
- amazon-web-services - 如何通过 N-1 次成功部署绕过 CodeDeploy
- flutter - 如何强制 Container 在 Flutter 中拥有其孩子的高度?
- express - TypeORM 和 Express 中间件
- firebase - E/StorageUtil(5389):获取令牌时出错 java.util.concurrent.ExecutionException:com.google.firebase.internal.api.FirebaseNoSignedInUserException
- java - 无法在 com.itextpdf:itext7-core:pom:RELEASE 收集依赖项
- python - 为什么在我点击按钮之前会出现测试标签?
- sharepoint - 在 C# 代码(和 Postman)中从 SharePoint 访问匿名共享链接会导致 403
- c++ - Serial 的输出完全错误-> 我做错了什么?
- c++ - avrogencpp 可以为模式中的每种类型生成单独的头文件吗?