New Github repo: URLParams

I spent more time than I’d have liked last week fixing an issue related to the intermittently incorrect appending of UTM parameters to URLs. Basically, the code worked fine if the link was “basic”, but if it already had  parameters, a second question mark would get added. Since URLs cannot have two question marks, the link would break.

Adding parameters to links sounds simple, until you “roll your own code” and discover issues like– making sure your parameters are URL encoded, and checking to see if the link already has parameters, etc. I decided to capture these hard-won lessons in a JavaScript class called URLParam, and it’s freely available at GitHub.  (It’s worth mentioning– although ES6 classes enjoy wide support across Chrome, Firefox, Edge, Safari, etc., they are not supported in any version of Internet Explorer.)

I hope you’ll find this useful– both in the sense of finishing a coding task faster, and having fewer issues to resolve after deployment.

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”