Education Through Minification

While puttering around with JavaScript minification earlier this morning, I noticed this:

if ( a % 5 === 0) { b += “buzz” }

was transformed into this:

a % 5 === 0 && ( b += “buzz”)

I’ve seen similar JavaScript cleverness with the OR operator to either preserve a previously defined object or create a new one if it isn’t already defined, but it never dawned on me a similar thing could be done with an AND operator simulating an if statement.

CommonSpot ADF’s renderScriptOnce method

A tiny green sprout with a single leaf pokes up out of an otherwise dead houseplant.

A problem common across many CMS platforms is managing the loading of third-party JavaScripts, such as JWPlayer. You could make them available for any page in your website by including them in a global header or footer, but that approach is lazy and wastes bandwidth. A better approach is to include third-party JavaScripts on only the pages where they will be used.

For example, pages with embedded videos get the JWPlayer linking, but the pages lacking videos do not. This is fairly straightforward– just include the third-party JavaScript in the output of the plugin, render handler, etc. with which it is associated (i.e. your video element/plugin links to the JWPlayer script).

But what if a page has multiple instances of that video element/plugin?

Continue reading “CommonSpot ADF’s renderScriptOnce method”

Ode to the MOD operator

Modulus Operator

I believe the modulus operator is the most underrated mathematical operator of any programming language. It is a clean, simple mechanism for linking a finite number of options with an infinite number of screening criteria.

Like the 12 animals in the Chinese Zodiac against anyone’s birth year, past or future:

This is convenient because more often than you might expect, the actual numbers are less important than the relationships between the numbers.