Obscure Rails 3.1 asset pipeline feature messes with my head

For some time, I have been in the habit of appending a datestamp to my image assets whenever I update them. This is a low-tech, reliable cache-buster. For example, if I add a new icon to the sprite image “app-icons-20110901.png” (last edited 1 September 2011), I would change the name to “app-icons-20110909.png“, and change the matching CSS from

.test {
    background-image:url(/images/sprites/app-icons-20110901.png);
}

to

.test {
    background-image:url(/images/sprites/app-icons-20110909.png);
}

By changing the name of the file, I can guarantee that as soon as a browser gets the new CSS, there is no risk of it re-using an old version of the sprite file from cache. This works great on static sites that are updated rarely, and on sites where you haven’t gone to the trouble of implementing a more sophisticated system of (image) asset fingerprinting.

Rails 3.1 comes with fingerprinting baked in as part the new asset pipeline. Unfortunately, the asset pipelining breaks in the presence of my manual fingerprinting efforts. Rails refuses to serve up an image asset whose file name ends in a dash followed by more than 6 digits:

  • /app/assets/images/app-icons-2011.png is fine
  • /app/assets/images/app-icons-201109.png is fine
  • /app/assets/images/app-icons-2011090.png doesn’t work
  • /app/assets/images/app-icons-20110909.png doesn’t work

The error reported is a straightforward Routing Error:

No route matches [GET] "/assets/app-icons-20110909.png"

So code like this in a stylesheet will not work:

/* application.css.erb */
.test {
    background-image:url(<%= asset_path 'sprites/app-icons-20110909.png' %>);
}

(Also, running bundle exec rake assets:precompile will not generate a matching MD5 fingerprinted image under /public for the affected file.)

I haven’t gone into the source code to find out exactly where this happening (I think this all goes on under the hood in Sprockets rather than in Rails itself) but as the old joke goes, the solution is pretty simple:

Doctor, doctor! It hurts when I do this!

Well, stop doing that, then.

If you’re doing Rails 3.1, just let it take care of the fingerprinting, and everything will be fine.

Further reading:

The Non-Scenic Route

Brilliant article by John Lanchester in the London Review of Books: “The Non-Scenic Route to the Place We’re Going Anyway

Quarterly GDP data don’t, on the whole, tend to make the person studying them laugh out loud. The most recent set, however, are an exception, despite the fact that the general picture is of unrelieved and spreading economic gloom. Instead of the surge of rebounding growth which historically accompanies successful exit from a recession, we have the UK’s disappointing 0.2 per cent growth, the US’s anaemic 0.3 per cent and the glum eurozone average figure of 0.2 per cent. That number includes the surprising and alarming German 0.1 per cent, the desperately poor French 0 per cent and then, wait for it, the agreeably frisky Belgian 0.7 per cent. Why is that, if you’ve been following the story, laugh-aloud funny? Because Belgium doesn’t have a government. Thanks to political stalemate in Brussels, it hasn’t had one for 15 months. No government means none of the stuff all the other governments are doing: no cuts and no ‘austerity’ packages. In the absence of anyone with a mandate to slash and burn, Belgian public sector spending is puttering along much as it always was; hence the continuing growth of their economy. It turns out that from the economic point of view, in the current crisis, no government is better than any government – any existing government.

Some summer reading

  • Charles Stross – Rule 34 A sharp and funny thriller set in 2020s Edinburgh, full of observations on the impact information technology might have on policing, politics, and our personal lives. Like many of Charlie’s books, I found the ending a bit too vague. He seems to like leaving you with questions and opportunities for you to use your imagination to fill in the details. Apart from that, brilliant.
  • James Gleick – The Information A history of how we deal with, well, information: language, writing, communication. Gleick spins a thread of discoveries, inventions, and insights from pre-literacy right up to present information age. It’s the earlier chapters I found most compelling, though. The book is subtitled, “A History, a Theory, a Flood,” and once Gleick gets through Shannon and into the era of the Flood, many of the anecdotes and details feel incomplete, or drift off into unsatisying speculation. Gleick is at his best as a chronicler, but the story of the information Flood has only just begun, so it’s hard to paint a complete picture. The Information actually complements Rule 34 very nicely: together they vividly cover both the past and the future of the subject.
  • Kate Griffin – A Madness of Angels Urban Fantasy didn’t used to be my cup of tea, but I’m discovering more and more hardboiled Urban Fantasy books that sit with me rather well. I’m not sure if this strictly qualifies as hardboiled, but despite a certain tendency towards overly descriptions it doesn’t have any of the goth-ish faux-noir sensibilities that I (perhaps unfairly) associate with the genre. Tough, well-drawn characters and a present-day London that is both gritty and filled with thinly disguised wonder are going to have me coming back for more.
  • Harry Connolly – Game Of Cages No doubt whatsoever about the hardboiled nature of this one. I read the first book in this series, Child Of Fire a couple of months ago after having read Harry’s guest posts on Charlie Stross’s blog. Harry’s Twenty Palaces books tackle Lovecraftian horror with a very head-first American hardboiled flavour in the same way that Charlie’s Laundry books cover it with a uniquely British twist. His new book, Circle of Enemies is just out, and will be on my next Amazon order.

  • Derek Landy – Skulduggery Pleasant 3: The Faceless Ones Alex got the first book in the Skulduggery Pleasant series for Christmas, and declared it “awesome”. He persuaded me to read it, and damn it, he’s right. It’s funny, and full of fast-paced action and snappy dialogue. So now I’m following behind Alex as he works his way through the whole series. (I wish he’d hurry up on book 4; I’m eager to find out what happens next!)
  • Lev Grossman – The Magicians Very mixed reviews on Amazon for this one, and I can see how it might not suit everyone, but I loved it. It builds up a complex set of relationships very quickly, but it doesn’t linger lovingly on them, or tease out every nuance, because it moves through the plot at a blistering pace. It appears blatantly derivative of Narnia, Harry Potter, and The Secret History, but it blends these old and new archetypes with an insouciance I found entertaining. In fact, the multiplicity of influences is exactly what keeps it interesting: just when you think you know what the next chapter will bring, it actually turns in a different direction.

Mobile web ancestry

Joe Celko has a nice new article on Simple-Talk.com about how easy it is to write SQL queries that unconsciously adopt the idioms of sequential media, i.e. magnetic tape.

When you sit in a live theater, you cannot do a close-up, pan shot, zoom, dissolve or other effect that are common in movies today. Early silent films parked the camera in one position and mimicked a theater experience. This is a general systems principle that the new technology will first mimic the previous technology before it finds its own voice.

The mobile web has two immediate genetic parents: mobile apps and the desktop web. When a mobile website can tries to follow in the footsteps of either parent too closely, it feels wrong. Encountering a mobile website that locks your vertical viewport size and forces you to use a custom scrolling algorithm is just uncanny-valley weird; whereas a site full of great content and links that doesn’t enjoy the full depth and richness of the “main” site feels unsatisfying.

Remember, though, that we haven’t been using magnetic tape as a mainstream storage medium for databases for some time now, but the idioms are still ingrained. The “classic” web has been around for a scant 20 years, and is still evolving. Mobile apps, as introduced by the iPhone, are only 3 years old

The mobile web’s parents are a teen and a toddler. Is it any wonder that it hasn’t found its own feet yet? Right now, it’s an ugly duckling inside a cocoon. Some onlookers may expect to see it emerge as a swan or a butterfly, but I’m betting on something much more interesting and strange.

More on Google and online identity

“Google seemingly split on pseudonymous Google+ accounts and Google Profiles – It’s okay until it isn’t” by Tateru Nino (via Dave Bell on Making Light) is another interesting look at the side effects of the rollout of Google+. It seems that Google+ and Google Profiles share some aspects of a honeypot for people with the audacity not to use their full real-world identity online so they can be more effectively marketed to.

And then there’s “Last Post” over at Cockpit Conversation (via Sylvia on Making Light), which is another tale of someone losing access to their Gmail and blog (hosted by Google) because of a date of birth issue.

People blogging about these particular problems are the visible tip of the iceberg. There must be thousands of other people who are running up against the same issues. And unfortunately, unless you know someone inside Google, the only way to ask them for help with some really scary problems is to post in an open forum. (And seriously, if you’re not a computer geek with the knowledge to figure it out, losing access to your email can be terrifying.)

Despite all the people posting on that forum about date of birth problems preventing them from accessing their accounts, so far Google’s best official response there seems to be “Google is aware that mistaken dob entries have precluded some users from entering the Google+ Project in it’s initial field trial.”

For a company whose motto is “don’t be evil,” and that is filled with engineers driven to make the internet a better place not just for Google users, but for all of us, this kind of hands-off take-it-or-leave-it approach is…disappointing.

For reference (because people have been asking), we haven’t heard anything from Google about our own particular situation, either formally or through back channels. As many people have pointed out, we could use the account recovery process to claim that we made an error, and enter a fake date of birth that shows Alex is over 13. But this is the only circumstance in which Google allows you to change the date of birth in your profile. Once it is in there, it is in there for good, and there would be no way for Alex to reset it once he is old enough. This may be problematic if he decides wants to keep using this particular Google account in the future.

How to fail at mobile web

Does this sound familiar?

  1. Build an iPhone and Android app first.
  2. Realise that there are other platforms out there.
  3. Build a mobile website (aka “HTML5 app”) for the other platforms. Aim to make the mobile web site behave the just like the iPhone and Android app, “only in HTML5”.
  4. Be disappointed when the mobile web site runs like crap on a Nokia, and doesn’t render at all on a Blackberry 5.
  5. Starve the mobile website of resources and attention in favour of the shiny native apps that give good demo.

It doesn’t have to be like this. Don’t consider the mobile web as just something to “fill in the gaps.” iPhone owners use the web, too. Research shows that page load times matter. If an iPhone user clicks a link to your site, what do you think will make them happier?

  • 3 seconds to load a nicely mobile-optimized web page, with fewer bells and whistles, but with clear calls to action and a “buy” button
  • 3 minutes to hit the app store, download, install, and launch your app

Sometimes you don’t want to create a new account with a web store just to make a simple purchase. Sometimes you don’t want to download an app just to interact with a service. The mobile web is different. Play to its strengths, not its weaknesses.