开发者

how to reload only scripts through firebug

I'm doing lot of ajax stuff lately. Scenario that I repeat over and over is:

  1. load page
  2. chan开发者_开发问答ge some scripts for that page
  3. 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?


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:

function addJS_Node (text, s_URL)
{
    var scriptNode                      = document.createElement ('script');
    scriptNode.type                     = "text/javascript";

    if (text)  scriptNode.textContent   = text;
    if (s_URL) scriptNode.src           = s_URL;

    document.head.appendChild (scriptNode);
}

addJS_Node (null, 'Path_to_JS/ResetTimersAndEvents.js');

addJS_Node (null, 'Path_to_JS/JS_Under_Test.js');
// etc.


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:

XRefresh is also able to replace externally linked JS file with updated version without reloading whole page.

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.


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 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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜