…so I know you’ve looked around the net for a good method to parse URL variables with javascript, and I’m sure that you’ve found some elegant method that looks something like:
function parseLocation() {
var turl = window.location.search;
ar = turl.split('&');
var b = {};
for (var i = 0; i < ar.length; i++) {
var c = ar[i].split('=');
b[c[0]] = c[1];
}
return b;
}
and you’ve thought, “oh, look how nice and compact that is. I shall use it post-haste!” Well, let me, as Mr. Guy Who’s Gotten Plenty Of Grumpy Complaints About This, light a candle rather than curse your darkness.
It is a good method, don’t get me wrong. It works great in theory. The problem is, say you copy/paste you url into, say, your Blogging Software of choice*. It might then re-interpret your url from:
http://post-hipster.com/parsey.html?var1=hey&var2=mambo&var3=fagabefe
into
http://post-hipster.com/parsey.html?var1=hey&var2=mambo&var3=fagabefe
and, on some browsers*, no amount of encode() or decode() will make that go away, which, in essence, changes your parsed variable names int “amp;var2″ and “amp;var3″
My solution, however inelegant, is to make the function explicitly look for the variables in question:
function parseLocation() {
var turl = window.location.search;
ar = turl.split('&');
var b = {var1:'default_for_var1', var2:''};
for (var i = 0; i < ar.length; i++) {
var c = ar[i].split('=');
if (c[0].indexOf('var1') > -1) {
b['var1'] = c[1];
} else if (c[0].indexOf('var2') > -1) {
b['var2'] = c[1];
} else if (c[0].indexOf('var3') > -1) {
b['var3'] = c[1];
}
}
return b;
}
I know, I coulda just RegEx’ed the ‘amp;’ away, but this way prevents any other encoding mishaps. If this was a global function, across a buncha different pages, I probably would just look for and get rid of the ‘amp;’
So there you go. Unfortunately, URL parsing isn’t always as nice as we want it to be.
* unfortunately I can’t be more specific than this, because I haven’t yet been able to duplicate the error on any browser / os combination I’ve tried, but I’ve gotten enough complaints about it to know that it exists.
This one fires on pretty much all cylinders for me:

The video capture is not, in fact, the Arsonists Caught on Tape, but of the ad that preceded the video of the aforementioned arsonists, in which this guy burns all his luggage cause now he’s got gotomeeting and is going to Do More while Travelling Less, and apparently never go on vacation again. I’d qualify this more as a ‘hah’ than a ‘lol’.
…so Jessica’s mom, she lives out in Santa Fe, and she has a neighbor that’s very, very old. And, being as they’re in the High Desert, where the air is thin, this old lady, she’s got an oxygen tank she lugs around with her. And so she wants to park right in front of her house, and she doesn’t want anyone else to park there. So she figures, I’ll go get myself a “Handicapped parking” sign, put it up on my front gate. That way, no one else will park in front of my house. So she goes out and gets one, but I don’t think she read it too carefully:
…say you’re using Javascript to reload an image periodically, say, every 60 seconds, and the image never refreshes. If you look for help across the web (as undoubtedly you have, since you’re here now, right?) you’ll find a) A bunch of people telling you to tag on a url param that’s a random number, and b) A bunch of snippy JS people who will insist, very condescendingly, you haven’t set your response headers correctly, and it’s not javascript’s problem, and you should think before you post such stupid questions.
Well, it turns out they’re both wrong. With the latter, the problem is, a browser has an internal page-level memory space that it will “remember” image urls with. When you create an image in javascript (via an Image() object or innerHTML, take your pick), if that image src has already been requested once on that page, the browser will give you that image from its internal memory, regardless of the image’s Expire or Cache-control headers. It won’t be put into the browser’s cache, sure, but it still stays in the browser’s memory for as long as you’re viewing that page.
The former seems to be the quick fix - the image src is always unique, so it’s not in memory, and the browser will ping the server for the image. But this approach fails if you’ve actually set your target image’s headers correctly (which of course you should). Because with this approach, the server sees each request as unique, and will send a new copy of the image down the pipe, regardless of if you wanted it to or not. You’re similarly screwed if you’re working on a high-traffic sites using a CDN - since a CDN (usually) contains cached copies of files from a master server, adding the cache-busting parameter to an image on a CDN will force the CDN to re-acquire the image from the master server before sending the image, which defeats the whole purpose of using a CDN in the first place.
The solution, unfortunately, is pretty hacky - to add a hash mark (#) to your image before applying a cache-busting parameter, i.e.:
function updateImage() {
document.getElementById('image_arena').innerHTML = '<img src="/your/constantly/updating/image.jpg#e' + Math.random() + '">';
setTimeout(updateImage, 60000);
return;
}
This will psyche out the browser into thinking the URL of the image is unique (”Hey Firefox, look over there! PSYCHE!!11!”), but in the actual HTTP request anything beyond the hash gets stripped before the request is made. So, the browser thinks the request is unique and pings the server for it, but the server will know for reals wether or not the request is new, and send the appropriate 200/304 response*. Everyone’s happy, except for possibly your sense of aesthetics, since that is an ugly url you’re passing. But since you’re the only one who will probably see them, you’ll be alone in your secret shame.
*Yes, I did just bust some HTTP response codes.
Many years ago Christina Dixcy and I went to the Barnes & Noble on Union Square to hear DFW read from his just-released Brief Interviews with Hideous Men. There might have been other people involved, I’m not sure, as it was a long time ago. Anyway, as Christina and I were among the privileged (read “smug, hipster”) few who had actually read Infinite Jest (me, twice, cause I’m geeky and post-modern that way, and Dixcy, with an ingenious method of physically cutting the book into 3 mini-books (with their accompanying footnotes, natch) to facilitate subway reading, cause that thing was way to impractical to read underground, man).
And so he reads, I don’t remember which story, and then, it’s over, and we go to get in line to get our books signed. I admit I’m a little starstruck and nervous about the encounter. And the guy ahead of us, it’s his turn, and here he is, probably as shy and starstruck and nervous as I am (well, not as shy), and he’s standing in front of a guy whose work he admires, and wants him (DFW) to know that he’s a fan, and has already read the book David is touring to promote the release of, but not quite sure what to say, on account of nerves, probably, so anyway he blurts out what had to be the first thing that popped into his head, “Hey, so did your father really wave his dick at you when you were thirteen?” (a reference to a story in BIWHM). I couldn’t see, but I’m sure dude cringed the very second it left his mouth, sucked in his breath, knowing he had said the Precisely Wrong Thing. DFW sighed, looked up, said, “fiction: from the Latin Fictae, meaning ‘made up’” and gave him his book. Dude slinked off, probably to a bar, to lament that he had met a great author and Blown It like an Anthony Michael-Hall character.
Pressure was off of me, though - cause I was next, and instead of standing there silently or uttering a voice-cracking “I-I-I-I’m a big fan of your work!,” which is what I probably would have done, I now had a “oh man, can you believe that guy?” bond with my new pal Dave. He signed my copy with the above statement, saying something about how he used to make signatures more personal, but after something was taken out of context, he had stopped. He, Dixcy and I shared a slightly obscure Monty Python reference, had a nice friendly laugh, and we were on our way. On the subway home, I reflected that he seemed like a nice guy, I was glad to have done it (like I said, I was pretty nervous about the whole book-signing thing), and most importantly, I was glad I wasn’t the guy in front of me in line.