为什么 Chrome 不会在更改时更新 Typescript 源文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18658185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:51:10  来源:igfitidea点击:

Why Chrome doesn't update Typescript source files on change?

google-chromecachingvisual-studio-2012typescriptgoogle-chrome-devtools

提问by Ali Essam

I'm working on a TypeScript (0.9.1) project using Visual Studio 2012 with the latest Web Essentials as the IDE, and i debug using Chrome Developer tools.

我正在使用 Visual Studio 2012 和最新的 Web Essentials 作为 IDE 处理 TypeScript (0.9.1) 项目,并且我使用 Chrome 开发人员工具进行调试。

Recently, and most probably after Chrome update (cur. Version 29.0.1547.66 m), typeScript files don't get updated after i edit them, and on the other hand the corresponding compiled js files are updated, but it seems that somehow the functionality still depends on the non-updated version of the sources.

最近,很可能在 Chrome 更新(当前版本 29.0.1547.66 m)之后,我编辑它们后没有更新 typeScript 文件,另一方面,相应的编译 js 文件也更新了,但似乎功能以某种方式仍然取决于源的非更新版本。

Solutions tried and failed:

尝试过但失败的解决方案

  • Rebuild the full solution.
  • Hard refreshing (Shift + F5) the local host site on chrome
  • Deleting Source map files and generate them again.
  • 重建完整的解决方案。
  • 在 chrome 上硬刷新 (Shift + F5) 本地主机站点
  • 删除源映射文件并重新生成它们。

After some trials it looks like even a request to download the ts source files yields the non-updated version (http://localhost:1198/xxx.tse.g)

经过一些试验,看起来即使是下载 ts 源文件的请求也会产生未更新的版本(http://localhost:1198/xxx.ts例如)

It seems that the problem gets partially fixed after full restart (windows 8 if it matters), the source files are updated in chrome, but once i change it again, the same problem appears.

似乎问题在完全重新启动后得到部分修复(Windows 8,如果重要的话),源文件在 chrome 中更新,但是一旦我再次更改它,就会出现同样的问题。

Another solution was using incognito, as it seems that it's a caching problem.

另一个解决方案是使用隐身模式,因为它似乎是一个缓存问题。

My question:

我的问题

Is caching typeScript files that way is caused by a problem in the configurations of the project (even it was working before), or this is a bug in the new version of Chrome ?

以这种方式缓存 typeScript 文件是由项目配置中的问题引起的(即使它之前工作过),还是新版本 Chrome 中的错误?

采纳答案by basarat

If you are serving from IIS, We have manually disabled cache in our web.configfile :

如果您从 IIS 提供服务,我们已在我们的web.config文件中手动禁用缓存:

<system.webServer>

    <httpProtocol>

      <!--TODO: Remove this block for production (//TODO: Remove this block for production) -->
      <customHeaders>
        <!--DISABLE CACHE-->
        <add name="Cache-Control" value="no-cache, no-store, must-revalidate" />
        <add name="Pragma" value="no-cache" />
        <add name="Expires" value="0" />
      </customHeaders>

    </httpProtocol>
</system.webServer>     

回答by Abdullah SARGIN

To I'm experiencing same problem. I solved this problem with chreome debug tools disable cache checked.

我遇到了同样的问题。我用 chreome 调试工具禁用缓存检查解决了这个问题。

My second problem, i wrote a lot of class into a same file. i splice every class to seperate file.

我的第二个问题,我在同一个文件中写了很多类。我将每个类拼接成单独的文件。

enter image description here

在此处输入图片说明

回答by Jan Aagaard

I solved this by removing the cached files manually. This can be done through Chrome's settings:

我通过手动删除缓存文件解决了这个问题。这可以通过 Chrome 的设置来完成:

  1. Click on Customize and control Google Chrome - the burger menu iconin the top right corner of the browser window.
  2. Select Settingsnear the bottom of the menu.
  3. Scroll down and click on the Show advanced settings...link.
  4. Click on the Clear browing data...button.
  5. Check Cached images and files. The other checkboxes can be left unchecked.
  6. Click on the Clear browing databutton.
  1. 单击自定义和控制 Google Chrome -浏览器窗口右上角的汉堡菜单图标
  2. 选择靠近菜单底部的设置
  3. 向下滚动并单击“显示高级设置...”链接。
  4. 单击清除浏览数据...按钮。
  5. 检查缓存的图像和文件。其他复选框可以不选中。
  6. 单击清除浏览数据按钮。

The 'Disable cache' checkbox in the network tab didn't work for me, nor did a Ctrl+F5.

网络选项卡中的“禁用缓存”复选框对我不起作用,Ctrl+F5 也不起作用。

回答by Eric Bowman

I don't know why it doesn't work normally. But even when you turn off caching it still doesn't work. What does work as a manual work around. If chrome dev tools is open then you can right click the refresh icon and do a hard reload (I do 'Empty Cache and Hard Reload') and it works.

我不知道为什么它不能正常工作。但即使您关闭缓存,它仍然不起作用。什么可以作为手动解决方法。如果 Chrome 开发工具已打开,那么您可以右键单击刷新图标并进行硬重新加载(我执行“清空缓存和硬重新加载”)并且它可以工作。

回答by Zerelli Seifeddine

I solved this like Jan Aagaard .

我像 Jan Aagaard 一样解决了这个问题。

Customize and control Google Chrome > Settings > Show advanced settings... > Clear browing data... > Check in 'Cached images and files' > Clear browing data.

自定义和控制 Google Chrome > 设置 > 显示高级设置... > 清除浏览数据... > 签入“缓存的图像和文件” > 清除浏览数据。

回答by Whistler

If anyone have the same issue on Visual Studio 2015 after installing ASP.Net 5 RC1. Check if the Browser Link Dashboard displays "No current connections" when running or debugging a DNX project a repair of the update will correct the issue:

如果有人在安装 ASP.Net 5 RC1 后在 Visual Studio 2015 上遇到同样的问题。检查浏览器链接仪表板在运行或调试 DNX 项目时是否显示“无当前连接”,更新修复将更正问题:

  • Close Visual Studio
  • Open Control Panel > Programs and Features
  • Right click on "Microsoft ASP.NET 5 RC1 Update 1"
  • Click "change"
  • In the ASP.NET 5 RC1 Update 1 Installer, click "Repair"
  • 关闭 Visual Studio
  • 打开控制面板 > 程序和功能
  • 右键单击“Microsoft ASP.NET 5 RC1 Update 1”
  • 点击“更改”
  • 在 ASP.NET 5 RC1 Update 1 安装程序中,单击“修复”