Webstorm Live Edit不适用于外部JavaScript文件 [英] Webstorm Live Edit not working for an external JavaScript file

查看:96
本文介绍了Webstorm Live Edit不适用于外部JavaScript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用外部JavaScript文件时,Webstorm 8的实时编辑功能似乎不起作用(即包含在< script src =script.js>< / script> 在我的HTML中)。只有在我刷新页面后,才会显示外部JavaScript文件中的更改。

The Live Edit feature of Webstorm 8 doesn't seem to work when using an external JavaScript file (i.e. when included with <script src="script.js"></script> in my HTML). Changes in the external JavaScript file appear only after I refresh the page.

其他方案的工作正常 - 例如当我开始调试时,当我更改HTML或CSS文件时,Chrome中的页面会更新,当我在< script> 之间编写一些JavaScript代码时,事情也会起作用HTML中的< / script> 标记。

Things work just fine for other scenarios - e.g. when I start debugging, the page in Chrome gets updated when I make changes to the HTML or CSS files, and things also work when I write some JavaScript code between <script> and </script> tags in the HTML.

问题是什么?

推荐答案

实际上,Live Edit适用于这两种情况。但嵌入式javascript的更改总是会导致页面重新加载,而外部javascript中的更改则会被热切换 - 就像HTML和CSS一样。但是,外部JavaScript代码的每次更改都不会导致页面立即更新:新代码会立即加载到浏览器中,但只有当您执行某些操作才能触发此新代码时,更改结果才会显示。例如,如果更改onClick处理程序并在alert中写入新文本,则单击后将看到新文本而不重新加载页面。对于由timer
触发的函数也是如此但是如果JS代码仅在页面加载时执行(而不是在特定事件上),则必须手动重新加载页面以查看结果 - 实时编辑不会强制执行新代码

Actually Live Edit works in both cases. But changes in embedded javascript always cause page reloading, whereas changes in 'external' javascript are hotswapped - just as for HTML and CSS. But not each and every change in external javascript code results in immediate page update: new code is loaded to the browser instantly, but the results of the change will be visible only when you do something to trigger this new code. For example if you change the onClick handler and write new text in alert, you will see the new text after the click without reloading the page. Same for functions triggered by timer But if the JS code is executed only on page load (and not on certain event), you have to manually reload the page to see the results - live edit doesn't force new code execution

另请注意,由于Chrome限制,hotswapping当前不适用于文件级变量 - 请参阅 WEB-7390

Note also that hotswapping doesn't currently work for file-level variables due to Chrome limitations - see WEB-7390

这篇关于Webstorm Live Edit不适用于外部JavaScript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆