如何通过firebug仅重新加载脚本
我最近做了很多ajax的事情。我一遍又一遍地重复的场景是:
- 加载页面
- 更改该页面的一些脚本
- 使用 ctrl+f5 重新加载页面并查看它是否有效
我想要做的是告诉 firebug 仅重新加载脚本而不是整个页面,因为标记是相同。无论如何要这样做吗?
I'm doing lot of ajax stuff lately. Scenario that I repeat over and over is:
- load page
- change some scripts for that page
- reload page with ctrl+f5 and see if it works
What I want to do, is tell firebug to reload only the scripts not the whole page because the markup is the same. Anyway to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,尝试尽量减少此类测试。在将其折叠到站点/页面之前,编写原子干燥代码和单元测试。 您可以在 Firebug 的控制台中快速完成其中一些操作。
接下来,如果您要重新加载的 JS 设置了间隔或事件侦听器,那么您需要在重新加载被测 JS 之前清除这些间隔并取消绑定这些侦听器。这意味着禁止匿名间隔和事件处理程序。
创建一个 JS 文件,根据需要调用
clearInterval()
、removeEventListener()
和.unbind()
。然后你可以在 Firebug 的控制台中运行这样的代码:
First, try and minimize this kind of testing. Write atomic, DRY code, and unit test before folding it into the site/page. You can do some of this quickly in Firebug's console.
Next, if the JS that you are reloading sets intervals or event listeners, then you will want to clear those intervals and unbind those listeners before reloading the JS under test. That means that anonymous intervals and event handlers are forbidden.
Create a JS file that calls
clearInterval()
,removeEventListener()
, and.unbind()
as necessary.Then you can run code like this in Firebug's console:
我认为 XRefresh 可能会有所帮助。它监视您的本地文件夹的更改,并在更改时(保存后)重新加载它们,而无需重新加载整个页面。
根据他们的网站常见问题解答:
不过,这有一些限制(我没有看到任何绕过它们的方法),您可以在他们的常见问题解答页面上阅读更多信息。
我仍然认为这比根本没有选择要好。
希望这有帮助。
I think XRefresh may help. It monitors your local folders for changes and reloads them when they change (after you save) without reloading the entire page.
Per their site faq:
There are limitations with this though (and I don't see any way of getting around them) which you can read more about on their faq page.
I still think its better than having no option at all.
Hope this helps.
我认为你真正需要的是自动化测试。编写测试,然后在更改代码后重新运行它们。
在 Firefox 上执行此操作的最佳方法是 webdriver。
I think what you really need is automated testing. Write your tests and then just rerun them after making a code change.
The best method for doing this on firefox is webdriver.
Firefox 目前还没有办法做到这一点。
如果标记相同那么 ctrl+f5 有什么问题吗?我猜您不想丢失表单字段中的数据?这又会导致问题,因为如果您只是重新加载脚本,并且这些脚本具有在表单字段更改时触发的事件,这些事件将永远不会触发,并可能导致页面最终处于不应该处于的状态
。有一些浏览器插件允许您通过单击按钮自动填写带有预定义值的表单字段,这可能是重新加载脚本的一个很好的替代方案。看起来这个 Firefox 插件就可以做到 https://addons。 mozilla.org/en-US/firefox/addon/autofill-forms/
Firefox currently has no way of doing this.
If the markup is the same then what's wrong with ctrl+f5? I'm guessing you don't want to loose the data in the form fields? This again causes problems as what happens if you just reload the scripts and those scripts have events that fire when form fields are changed, these events will never firing and could result in the page ending up in a state it shouldn't be in.
There are some browser plugins that allow you to automatically fill in form fields at the click of a button with pre defined values, this may be a good alternative to reloading just the scripts. It looks like this firefox plugin will do just that https://addons.mozilla.org/en-US/firefox/addon/autofill-forms/