Closing an eye on bad practices
You know how some people just loooove to bash Internet Explorer, considering it one of the worst things that happened to the Internet, the arch enemy of web developers and the only browser where bugs happen? Well, not for me! My nemesis is Firefox!
It was the end of a long and arduous journey towards a better zoom feature for our web catalogs and just when everything seemed to ready for deployment, Firefox happened!
Long story short, there was a weird flickering after the first page zoom. Our scaling process involved swapping the image source dynamically with higher quality ones and that didn't sit well with Firefox. With the help of this blog post on Firefox Flickering I managed to find a solution but it was nasty.
I already applied the change after the new image was preloaded but it wasn't enough. I had to create similar images, with the same size and css style and in the visible part of the DOM, so they will be rendered. In my case, they were absolutely positioned right behind the good images, copying their size and class, and only after they were loaded I swapped the src
-es, without a flicker this time.
While this did fix the problem, it was a horrible mess. Having a new set of images to manage (and also scale) added an extra layer of complexity. I had to make sure they were properly hidden and unloaded, not only introducing new possible sources of bugs but also making the scale animation slower everywhere else, and all this for a 9% market share browser flicker problem.
After voicing my concerns, my colleague proposed to do a browser detection for Firefox. I know it's bad practice but..., he said.
He had a point. Browser detection is considered bad practice and is frowned upon, the recommended alternative being feature detection. However, sometimes it is the browser and not the feature.
The notions of good practice and bad practice are relative. For me, a good practice is something to follow almost blindly when you are a beginner and to ignore as you see fit when you have experience.
If a certain feature exists, you can be sure it exists with a purpose. The most important thing is not to follow what other consider to be best practice but to understand why it is a recommended way of doing things and understand when you should follow the advice and when not to. It's certainly not something to be ashamed not to do.
In the end, what I said before is still true: I've got 99 problems but a browser ain't one. And that's both because and in spite of good practices.