Preventing Firefox memory, processor bloat

If you’ve read this blog before, you know I’m a big Firefox fan. But the one problem that has dogged me is the inevitable bloat that Firefox suffers when open for long periods of time. I work in my browser all day, and after 8 hours it has usually gobbled up all the available RAM, and sucks processor cycles like a Dyson. Fortunately I’ve finally pinpointed the cause and several solutions.

Let’s start at the source. The Firefox team made a crucial usability decision, which is at the heart of the problem. They wanted to allow the user to recover any page that may have recently opened. So by default, Firefox keeps navigation history for all your open tabs, plus the last 10 tabs that you closed. The navigation history for each of those tabs — both open and closed — can hold up to a maximum of 50 pages (i.e. the number of URLs you can traverse purely through the Back/Forward buttons)

With no limit to the number of open tabs, plus the high limit on the Back/Forward navigation, it’s easy to see why Firefox slows to a crawl. If you do a lot of browsing in a lot of tabs, your memory disappears in a hurry. Managing all that extra memory causes the processor to work overtime to keep Firefox hippo moving.

There are two ways to fix this issue in a pinch. First you can simply restart the browser, making sure that it doesn’t save your tabs (you are prompted to save tabs at close by default). Second, you can clear the Recently Closed Tabs to eliminate a portion of the tab history bloat (History > Recently Closed Tabs > Clear Closed Tabs List).

For a more long-term solution, we need to mess with the system settings. Type about:config in the address bar to bring up Firefox’s complete configurations list. The latest Firefox versions present you with a warning before opening the page.

A warning: this page handles everything in your browser. Everything. Don’t mess with stuff if you don’t know what you’re doing.

In the “Filter” textbox at the top, enter

browser.sessionstore.max_tabs_undo

This setting controls how many closed tabs to track. Less old tabs = less memory usage. Double click the lone entry in the list and change the value from “10″ to “5.”

Back to the filter box, enter

browser.sessionhistory.max_entries

This setting controls the navigation history limit. Double click the entry and drop the value from “50″ down to “25″.

Close the about:config tab and restart your browser.

Your mileage on these tweaks will vary depending on your system specs. If you can go a day of heavy browsing without hitting the creep, slowly increment the settings back up, until you hit the sweet spot.


iPad Flash decision: bad blast from the past

Reviews for Apple’s iPad are all over the place. Personally, I feel that tablets have tried and failed enough times in the general consumer market to call the concept dead. iPad will likely find adoption in the same niche’s as its predecessors: hospitals and other similar venues where it can effectively replace a manilla folder of documents.

Instead, I find the lack of Flash support more interesting to consider. This seems like a terrible omission for a device that Jobs touts as “the best browsing experience you’ve ever had” (around 0:30). I don’t know about you, but *my* browsing experience would be far less than perfect without access to the de facto standard video streaming technology.

The decision was apparently made due to compatibility problems

Apple does not support Flash because it is so buggy. Whenever a Mac crashes more often than not it’s because of Flash. No one will be using Flash. The world is moving to HTML5.

That may be where the web world is headed, but the iPad is entering a market nowhere near that reality. This just screams classic Apple mindset. They may share the mantra “Everyone else’s stuff is crap” with Microsoft, but Apple tacks the phrase “and that’s why you can’t use it,” onto the end.

I thought that Apple had figured out the market, how to balance a closed platform in order to maintain stability and skyrocket profitability. The Flash decision definitely throws that balance off kilter, and now I’m curious to see if they’ll fall back into the decision-making style of the PC wars in the late 80’s and early 90’s (Note to the kiddies: Mac wasn’t always “cool.” They lost a lot of weight and their acne cleared up just as you entered buying age).

They can get away with dictatorial control over platforms like the iPod and iPhone because they are very focused devices. However iPad is a closer technical cousin to the laptop than the smartphone, and the last few years of App Store and iTunes revenue may be skewing their vision on this one.

My gut tells me they are using iPad to push public perception away from Flash and toward HTML5. There’s no way they’ll make such a play on the Mac platform, but the iPad offers very controlled environment to test the waters. If people (continue to) complain, they’ll publish the iPad Flash patch that they’ve already got sitting on the shelf. Trust me, it’s there.

Update: This image sums up the problem for me quite nicely.
ipad vs netbook bullet list


Get HTTP status code of cURL call in PHP

With all the fancy cURL-based API’s out there these days (Facebook and Twitter immediately come to mind), using cURL to directly access and manipulate data is becoming quite common. However like all programming, there’s always the chance for an error to occur, and thus these calls must be immediately followed by error checks to ensure everything went as planned.

Most decent API’s will return their own custom errors when an internal problem occurs, but that does not account for issues dealing directly with the connection. So before your application goes looking for API-based errors, they should first check the returned HTTP status code to ensure the connection itself went well.

For example, Twitter-specific error messages are always paired with a “400 Bad Request” status. The message is of course helpful, but it’s far easier (as you’ll see) to find the status code from the response headers and then code for the exceptions as necessary, using the error text for logging and future debugging.

Anyway, the HTTP status code, also called the “response code,” is a number that corresponds with the result of an HTTP request. Your browser gets these codes every time you access a webpage, and cURL calls are no different. The following codes are the most common (excerpted from the Wikipedia entry on the subject)…

  • 200 OK
    Standard response for successful HTTP requests. The actual response will depend on the request method used. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request the response will contain an entity describing or containing the result of the action.
  • 301 Moved Permanently
    This and all future requests should be directed to the given URI.
  • 400 Bad Request
    The request contains bad syntax or cannot be fulfilled.
  • 401 Unauthorized
    Similar to 403 Forbidden, but specifically for use when authentication is possible but has failed or not yet been provided. The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource.
  • 403 Forbidden
    The request was a legal request, but the server is refusing to respond to it. Unlike a 401 Unauthorized response, authenticating will make no difference.
  • 404 Not Found
    The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible.
  • 500 Internal Server Error
    A generic error message, given when no more specific message is suitable.

So now that we know what we’re looking for, how do we go about actually getting them? Fortunately, PHP’s cURL support makes performing these checks pretty easy, they just don’t make the process plain. We need a function called curl_getinfo(). It returns an array full of useful information, but we only need to know the status number. Fortunately, we can set the arguments so that we only get this number back, like so…

// must set $url first. Duh...
$http = curl_init($url);
// do your curl thing here
$result = curl_exec($http);
$http_status = curl_getinfo($http, CURLINFO_HTTP_CODE);
echo $http_status;

curl_getinfo() returns data for the last curl request, so you must execute the cURL call first, then call curl_getinfo(). The key is the second argument; the predefined constant CURLINFO_HTTP_CODE tells the function to forego all the extra data, and just return the HTTP code as a string.

Echoing out the variable $http_status gets us the status code number, typically one of those outlined above.


Xenocode Browser Sandbox – Web designers rejoice!

Update:

Xenocode has decided to eschew usability in favor of…well nothing really. In order to use the browser sandboxes now, you must “initialize” them from the site, which amounts to downloading the files you need in order to execute the sandbox.

You can circumvent this genius decision by downloading the browser of choice, then open Windows Explorer and browse to C:\Documents and Settings\[USERNAME]\Local Settings\Application Data\Xenocode\Start\Cache. There you will find folders for each browser (e.g. ie6, ie7, ie8…), and if you drill down a few folders more, you’ll find an executable. Copy that to your desktop, and you can load the browser on demand whenever you want. There’s a whole post with details and insights. Bad, Xenocode, bad!

Finally. That’s all I have to say.

A company called Xenocode has taken all the major browsers and packaged them into contained executables, which you can download and run from your desktop. That’s no big deal, per se, since you can just install them.

BUT, they have self-contained packages for IE 6, 7, and 8. And they work. Beautifully.

If you’re like me, you’ve tired (and hated) the ridiculously complex solutions to circumvent Microsoft’s genius decision to ingrain IE into the Windows operating system. If you’re also like me, you’ll jump up and down when you download and run the IE6 sandbox in two steps. Okay, I didn’t jump, just bounced in my chair a bit, but still…

It appears to be Windows-only, but every designer should have access to a Windows box for obligatory IE testing fixing. Now go test, and be satisfied.


Trouble logging into anything Google from Firefox

400 Bad Request
That’s what I keep getting everywhere I go in the Google universe for the past several days using Firefox (using latest stable release, v3.0.6). I know I’m not the only one, I’ve found a plethora of recent support posts discussing the same issue. Normally I’m the one writing here to say “Hey, look out for this one, here’s how to handle it.” But this time I’m at a loss.

I automatically attribute any and all odd Firefox behavior to my ridiculous extension collection. There are so many, and sometimes one of them will get out of date and go all bull-china-shop on me. So I start disabling the most likely suspects…then a few more…finally all of them. Google still won’t behave. I go so far as to reset my Firefox profile (Beginners: try the safe way; Experts: go full monty). I log in once, but the behavior rapidly returns within a couple sessions (didn’t even have to restart).

Then I started looking at more systemic fixes, and I discover that clearing cache and cookies will fix the problem (with or without extensions in the picture), but again only lasts a few sessions. Since the problem is definitely with cache and/or cookies, I’m pretty much out of moves. I have no cookie or cache manager plugins that could be responsible, so this one rests squarely at Firefox’s furry feet.

At first I blamed Google, but then I saw similar behavior when trying to log into the Webmin interface I use for some servers. Logging in just kicks right back to the login prompt, with no errors.

In the meantime, I’ve switched all my logged-in Google activities (GMail, Analytics, etc.) over to Chrome, where I’ve had no problems whatsoever. I never used Chrome for routine browsing; the lack of extensions — notably AdBlock Plus and Firebug — really makes it unappealing. However I must admit that the overall UI is fantastic. If the Mozilla team doesn’t figure this cookie issue out soon, or if Google gets their act together and starts allowing Firefox plugins, I may make the full switch.

Still, I’d like to get back to a single window if possible, so if anyone has any other suggestions, I’m all ears.

Update: I’ve now reinstalled Firefox as well, to no avail. Until I find a permanent solution, I’ve installed another add-on called Clear Private Data, which gives you an icon to do exactly that. Now whenever Firefox acts up, I hit the button and continue. It still happens with ridiculous regularity, but at least the browser stays usable.


My Firefox extension collection

It seems to be some rite of passage for tech-focused blogs that they create a list of their favorite Firefox extensions. Who am I to break custom? If you’re not a web-developer, you can ignore the ones described as such, and consider the rest highly recommended. I have yet to find someone with as many extensions as me. You have been warned. Finally, you’ll find a screenshot demonstrating all these extensions in action at the bottom.


Adblock Plus with Adblock Filterset.G Updater

This is a fairly common standard. Adblock prevents ads from showing based on regex rules. I don’t have the time or inclination to write those rules, so I use Filterset.G to create them for me automatically. Between the two, I see no ads. Ever.

All-in-One Sidebar

It always drove me nuts that the download, extension, and theme panels popped up in their own window. This extension wrangles them into the sidebar area, just like the favorites. It includes an extra toolbar to toggle all the various sidebar areas, but can also contain any toolbar icon.

Better Gmail 2

Take Greasemonkey (which I don’t use), apply it to the Gmail interface, and you have Better Gmail 2. It adds some nice JavaScript-powered effects to the various pages, as well as additional information and links.

BugMeNot

I love using the BugMeNot service to circumvent those stupid sign-up requirements. I just want to read your article/download your software, get the hell out of the way! This plugin saves me from even having to visit the site. Right-click a login box, choose the BugMeNot option, and the login information is filled in automatically.

ColorfulTabs

Applies a different color to each tab, making each tab stand out a little bit better. Also includes options to associate the color with the content of the page.

ColorZilla

If you do any kind of design (but especially web design), you probably look at the web at least for some inspiration. This extension lets you grab any color displayed on any page. You can manually choose colors from the web-based palette, prepare a palette combination, and save your favorite colors.

Console2

Beefs up Firefox’s default error console. Search errors for specific text. Filter by JS, CSS, XML, chrome, or page content.

CustomizeGoogle

If Better Gmail 2 is the flash, this one is the bang. Goes deep into the top 16 Google properties and guts all the crap. Remove ads, remove sponsored links, force to secure connection (for things like Calendar and Docs).

Download Statusbar

Another generally popular pick. I use it for the same reason I use All-in-One Sidebar: it corrals Firefox’s bad habit of opening little extra windows. This one tucks downloads into a dynamic bar along the bottom. Each item is displayed as a progress bar, and includes a ton of download stats when moused over. After the download is done, double click to open/execute it, and the item is removed from the list automatically.

Extended Copy Menu

If you’re a developer, this is the must-have extension you’ve never heard of. It allows you to grab a copy of text from the browser in plain text format, i.e. without any special formatting. No more screwed up layout when you copy stuff into an e-mail or Word doc. Inversely, it also has a HTML copy option, which explicitly and cleanly grabs HTML along with the text.

Fancy Numbered Tabs

Replaces the closed graphic on tabs with a number. Like ColorfulTabs, I find it makes it just a little bit easier to navigate my tabs. It may bork the tab in some of the more elaborate themes.

Fasterfox

Another overall top pick. Fasterfox makes tweaks to Firefox’s configuration options (enter about:config into your address line to see them) to increase performance, sometimes drastically. Install, make sure it’s set to “Turbo Charged,” and you’re done.

Note: Fasterfox is currently marked as “Experimental,” which means you have to have an account on the Mozilla site to download it. I can say that it has worked fine for me, your results could vary (but probably not).

Firebug plus YSlow and Jiffy

At this point, this one really needs no introduction or explanation. If you do anything with the web, Firebug is a must-have. It has debugging options. Lots of them. JavaScript, CSS, XML, HTML, AJAX. This post is already too long, read the documentation for all the details.

YSlow and Jiffy are nice complements to Firebug’s standard functions. YSlow evaluates a given page and tells you how to speed things up. Includes links to the now-famous Exceptional Performance section of Yahoo’s Developer Network. Jiffy focuses on your Javascript and identifies which ones slowing up your page loads. Jiffy is also “Experimental,” like Fasterfox.

FireFTP

A solid FTP client is another required tool in any developer’s toolbox. I’ve tried all the usuals. CuteFTP, Filezilla, SmartFTP, WinSCP, each with their drawbacks. Lowsy interfaces, no reconnect, upload failure…Plus it’s another window I have to click, in addition to my browser and my coding interface. FireFTP has no downsides that I’ve found yet, sites right next to whatever site I’m working on, and is totally free.

Forecastfox

I don’t know anyone who doesn’t have this one. As if web-based weather wasn’t easy enough, now I don’t even need to browse anywhere to see the current, upcoming, and next day’s forecast. Mouseovers for radar and forecast details. Click any one for more information via AccuWeather.com (and with Adblock/Filterset.G, you won’t be bothered with their ads, either!). Automatic sliders for weather alerts.

Foxmarks Bookmark Synchronizer

Never worry about backing up your bookmarks again! Sign up for the free service (prompted automatically after installation), and Foxmarks will automatically maintain a remote copy of your bookmarks. If you’re away from your computer, you can access the bookmarks from their website. Side bonus: you can keep bookmarks in sync across multiple computers! I have an office laptop and a home desktop, and they always have the same bookmark list.

Gmail Notifier

There are tons of mail notifiers now, but if you use Gmail, this is one of the best. Easy setup, manage multiple accounts, automatic login, and a new mail alert slider.

IE Tab

Windows users have to go to the dark side for frequent security updates, and the occasional corporate site or intranet that Microsoft holds by the figs. Now you never have to leave the comforts of open-source home. This extension allows you to open a tab powered by the IE engine. Works with ActiveX plugins, so the Windows Updates site works fine.

Old Location Bar

I love the improvements in Firefox 3 save one: the auto-complete box that pops up as you type in the address bar. There’s so much going on in it, I find it impossible to discern the actual results at a glance. I don’t care about the page’s description, what’s the damn URL? Apparently I’m not alone. This extension brings back the simple listing behavior you saw in Firefox 2. Listed as “Experimental” like Firebug and Jiffy list above.

PDF Download

Ever click a link, only to get whacked in the face with that awful Adobe PDF plugin? Here’s an early warning system. When you click a PDF link, you are prompted with a series of options. Download it, open it using settings specified in the extension options, convert to HTML via PDF Download, use Firefox’s default behavior (usually aforementioned Adobe garbage), or cancel the download.

Bonus! Foxit PDF Reader

Okay, it’s not a Firefox extension, but I just can’t let one more person suffer under Adobe PDF Reader. That thing is a bloated, cpu-hogging, memory gobbling crap-fest. If all you need to do is view PDF documents (i.e. 99% of us), Foxit will meet your needs without running background clients (check your startup folder), and uses a fraction of the disk space.

Quick Restart

Ever notice that restart button you get when you install a new theme or extension? Now you can have that functionality whenever you want. Firefox still has a shifty memory leak, and this extension really saves me when it rears its ugly head. Hit the button, browser off, browser on. Tabs are saved.

ShowIP

Shows the IP Address of the site you are viewing in the bottom taskbar. A must for web guys, but security wonks and general tech enthusiasts will like this.

StumbleUpon

Ever notice your browsing habits get into a rut? You look at the same sites, or you friends keep sending similar YouTube videos of people acting like idiots. Break out! Install the plugin, create an account, set your desired topics, and click the button. SU will send you off to places previously unknown. Give your destinations a thumbs up or down, and SU will learn to tailor its offerings to you (a bit). StumbleUpon has been gaining more and more steam for its unique approach to browsing. However I saw the potential early on. Check out that “Member since” date!

Tiny Menu

If you’re a frequent flyer on the menu bar (File, Edit, View, etc. alogn the top), just go right past this. But if you’re a snobby tech elitist who has evolved past menus and into keyboard shortcuts, you’ll love Tiny menu. Condenses all the menu bar options under a single icon, allowing you to use the bar for other purposes, or eliminate it entirely. I stretch my address bar across the length, and give the search bar it’s own line beneath.

Update Notifier

Firefox does a good job of looking for updates routinely, but only does so at startup. So if you leave your browser open for long periods of time (or indefinitely, like me), you never get those notices. Enter this extension, which checks for updates at a routine interval (adjustable, 24 hours by default), and displays notifies you by highlighting the menu bar icon. The icon also allows you to run a manual check. Another click will automatically install the updates, and a third will restart the browser. All of these steps can be automated.

User Agent Switcher

Another must-have for web developers and designers here. It changes the user-agent string to whatever you want. In layman’s terms, you can masquerade as any other browser. Great for testign browser-specific stylesheets, as well as security settings.

Web Developer

Complements really well with Firebug, though there is a fair bit of overlap. I use it a lot to resize the browser for specific pixel dimensions (how does this page look at 800 x 600?), outline elements for layout debugs, reset my browser cache, find broken images, test my Javascript graceful degradation (or, often, lack thereof), or measure an elements actual size with the ruler. Plenty of other useful data outputs.


Here’s what all that looks like in action. It’s a bit of a departure from the default layout, but it works for me. Hopefully you’ll find something useful in that list as well.


The Greatest Firefox plugin

…ever.

http://amionmyspace.com