Firebug and javascript.options.strict

I’ve had some complaints recently that my site was taking an age to load in Firefox. In fact, anything built with base2 was performing very badly for some Firefox users. My advice to them was to disable Firebug. This solved the problem but I didn’t know why. I use Firebug and wasn’t experiencing any slow down.

Yesterday I received an email from Alex Robinson and now the mystery is solved.

Firefox allows users to set various preferences via the about:config URL. One of these settings, javascript.options.strict, generates various warnings and messages about your JavaScript code. Firebug then takes these messages and turns them into entries in the console. The latest version of base2 was generating about a hundred information/warning messages. Things like, “function does not always return a value”. A Firebug console entry is made up of several DOM elements, so a hundred messages generates several hundred DOM insertions. This is what was causing my site to perform so badly for some users.

I’ve since refactored the base2 code so that it no longer generates any warning or informational messages. I haven’t uploaded this code yet as I have made some other changes which I’ll blog about later.

I recommend that you test your own code with javascript.options.strict set to true.

Some more info on javascript.options.strict from Mark “Tarquin” Wilton-Jones.

Too bad the Prototype.js guys stubbornly refuse to make this one time change. Based on the looks of the code changes and because the assertions, that you really want to use that construct (like adding a pair of parens), are not required by the JS spec …

I recommend that you test your own code with javascript.options.strict set to true.

I always use firebug with javascript.options.strict set, and any warning has to disappear from my personal scripts or it’s no good.

That, though, pretty much requires most of the browsing to be done with firebug off, or many websites slow to a crawl and become pretty much unusable.

The real wtf is that people are surfing the web with firebug turned on for all sites…

It’s not much of a bother when JS warnings are set to false, and it allows you to easily e.g. inspect a website that seems interesting (just Ctrl-Shift-C and Firebug opens on the HTML tab and the HTML inspection mode activates)

The typeof operator does not issue a warning about accessing a undefined variable / property.

I am also a little worried that it thinks my optimised while(n=getNext()) should be flagged as a “test for equality (==) mistyped as assignment (=)”, but at least by the time someone starts using that sort of syntax, they usually know what they are doing, and will ignore the incorrect warning.

Just advice it checker that you really meant to do this by writing while( (n=getNext()) )

Actually, you’re overly complexifying it: it’s more than enough to just write if(document.onclick && document.onclick === myFunction) {, first you test if the property exists and only then to you test for your equality.

I did not miss anything in the article. This approach is simply wasteful and pointless. The former version is perfectly valid because JavaScript is loosely typed and can compare any variable type against any other variable type. Your code performs more than twice as slowly – a more than 100% performance hit, just because you think that a warning is an error.

It’s a warning not an error, meaning you can ignore it (that’s what my article was about, by the way, authors like you who mistakenly treat warnings as errors and think they all should be removed, even when the code is already perfectly valid). Stop trusting that stupid setting, ignore the warning.

Suggesting that people should use a typeof comparison instead of if(document.onclick) is equally silly, and will not work anyway. Some browsers use null as the default value, while others use undefined. typeof null is object, and that will never equate to undefined. My code will always give the correct response (and that part of your code will also correct the error of your typeof check). So basically your code is even more pointless, and exists _only_ for the purpose of satisfying an overly paranoid debugger. What a waste of effort for real browsers. Stop trusting that stupid setting. Learn to ignore it.

Warnings should really just be used to help you debug code and you don’t necessarily have to ‘fix’ them all, especially since it may just add more code to the scripts without giving any real benefit to the end user.

Error’s *need* to be fixed, warnings *may* need fixing (only if the script does not work).

Firebug is powerfull program but overflowing with bugs. It conflicts with quite a few websites making normal work impossible. In this particular problem I don’t know why should warnings or messages be so relevant that Firebug converts them into entries in the console and by that slows down loading of the website.