IE7 expected a string, identifier or number

JSON is nice to read. It’s also nice when parsers are for­giv­ing, but here we are.

I just spent ages chas­ing [what I thought was] a bug using $.getJ­SON in IE7 that turned out to be an issue with some­thing else entirely.

If you’re using $(el).css or .ani­mate with JSON, make sure you’ve ter­mi­nated all items cor­rectly and don’t have any hang­ing com­mas left over:

Hanging comma at end of JSON params

This case sent me par­tic­u­larly crazy as I was also deal­ing with an actual JSON request in the same gen­eral vicin­ity that I’d val­i­dated a bunch of times and seemed perfect.

Note to self: Before you go down the white­space and text encod­ing rab­bit­hole next time, make sure you’re actu­ally check­ing the right JSON!

# by Josh on April 19th, 2012 Tags: , , ,
|
1 Comment »

Some tips for mobile CSS

On “retina”/high DPI:

  • SVG sprites are a beau­ti­ful thing. Make the can­vas size work at a device ratio of 1, and capa­ble user agents (read: mobile Safari) will do the hard work for you. Don’t cre­ate a double-resolution sprite, because you’ll need to man­u­ally re-declare all your siz­ing and posi­tion­ing, which is no fun.
  • Opera sup­ports SVG but doesn’t bother to scale it. In most cases, this means a well-quantised PNG is going to be smaller.
  • Opera’s device-pixel-ratios are actu­ally expressed as ratios (x/y), as opposed to floats (1.5). I actu­ally think this makes a lot of sense, though I’m pretty sure they’ve already lost this battle.
  • Mozilla/Fennec doesn’t do ratios in a stan­dard way, either — their syn­tax is “min – moz-device-pixel-ratio”. They obvi­ously missed the part where browser pre­fixes are sup­posed to be, well, pre­fixed. This was done back in late 2010 and they looked at the –webkit imple­men­ta­tion first, before imple­ment­ing it in a very dif­fer­ent fash­ion with­out much debate. It’s a mind-bogglingly undis­cussed issue on Bugzilla and the wider Internet.
  • Android DPI val­ues for DevicesY­ouKnowAbout™ hover around the 1.5 mark. Any­thing lower than this and the device capa­bil­i­ties prob­a­bly don’t make it worth­while, and any­thing higher is prob­a­bly an iPhone. Higher res­o­lu­tion Android devices just don’t seem to exist, or, for the most part, report them­selves as exist­ing (March 2012 — yeah, the Nexus and Galaxy S2 and stuff are big, but don’t seem to be doc­u­mented as report­ing high DPIs).
  • Okay, so DPI val­ues aren’t quite that sim­ple. To quote A List Apart, “we don’t know what each device con­sid­ers a pixel and this is a prob­lem.” Read about it, test lots, buy Android devices if you want to be sure.

Mis­cel­la­neous gotchas:

  • Cer­tain Android vari­ants — I don’t have enough devices to test con­clu­sively — drop gra­di­ent back­grounds, opac­ity etc. (pre­sum­ably for per­for­mance rea­sons) despite hav­ing “A grade” capa­bil­i­ties in a lot of other senses. Make sure you do sim­ple things like hav­ing back­grounds and bor­ders on ele­ments that would have pre­vi­ously been divided by gra­di­ent con­trast. Your fea­ture­phone vis­i­tors will also thank you. In an ideal world you’d prob­a­bly pro­gres­sively enhance these kind of things, rather than patch­ing it up after­wards, but it’s easy to get caught up in the excite­ment of only need­ing to sup­port “A Grade” browsers (accept­ing that IE is suit­ably ban­ished from Mobile land) and just for­get. Don’t forget.
  • Beware HTML5 man­i­fests — they raise stor­age prompts that could scare some users in some browsers (“why is this site stor­ing info about me?). They’re also actu­ally not that effec­tive unless you pin an app to the home screen, so recon­sider your need to use one.
  • Fen­nec uses left/right swip­ing for access­ing browser UI. This is a pretty dumb design deci­sion, because it breaks left/right swip­ing ges­tures (think photo gal­leries). Expose an alter­na­tive UI (Next/Prev but­tons per­haps?) for browsers that don’t do touch events in this way.
  • Win­dows Phone 7. You’ve heard good things, right? Kinda. It’s def­i­nitely up there, but early ver­sions of this device (2011) had a browser that was more or less equiv­a­lent to IE7 with a few IE8 fea­tures thrown in for good mea­sure. I’m not both­er­ing to sup­port it. How­ever, even the lat­est ver­sions (March 2012) don’t sup­port touch events (!) so expect it to be even worse than Fen­nec for con­ven­tional swipe-driven mobile UI in the browser. It does have Can­vas sup­port, but appar­ently lacks SVG in the browser.
  • SVG gra­di­ent sup­port is patchy (prob­a­bly for sim­i­lar rea­sons Android devices choose not to ren­der CSS gradients)

Tips:

  • Use text-rendering: opti­mizeLeg­i­bil­ity; on head­ings as it does great things on the iPhone 4. (via Men­ac­ing Cloud)
  • Flash ads work. This is stag­ger­ing, but true. Expect that Android devices will suc­cess­fully dis­play Flash ads, and pay atten­tion to dif­fer­ent markup that gets adserved for these devices as it will pos­si­bly impact your CSS.
  • Image based ads scale down quite well. It’s tricky get­ting mobile inven­tory smaller than 300px wide, but if you’re expect­ing 240px devices then just use max-width:100% for this. It’s bet­ter than break­ing the lay­out or not serv­ing ads to these screens, not that there are many of them left.
# by Josh on March 6th, 2012 | No Comments »

You[r inner copywriter[/editor]] will love this.

[Visit] Tele­scopic Text.

Click [[any of] the [first [three]]] words.

(My for­mat­ting will make sense when you start using it)

# by Josh on February 16th, 2012 Tags: , , ,
|
No Comments »

A solution to Auspost’s unhelpful suburb/postcode license

Aus­tralia Post pro­vide a nice con­ve­nient CSV of all of their post­code data, and then pro­ceed to make the license quite prohibitive.

Com­mer­cial use? No. Open source mod­i­fi­ca­tion? No. Redis­tri­b­u­tion? Nope.

This is really annoy­ing, but thank­fully there’s another option. For your book­mark­ing plea­sure, enter https://github.com/joahua/AusPostcode. It’s a CC-BY licensed ver­sion of suburb/postcode data in both CSV and JSON for­mats (feel free to fork and sub­mit a pull request if you’ve got oth­ers) based on Aus­tralian cen­sus data that’s much more per­mis­sively licensed.

Happy free/open-source postcoding!

# by Josh on February 11th, 2012 | 4 Comments »

How to install Android Debug Bridge (ADB)

The lat­est Android SDK doesn’t ship with Android Debug Bridge (ADB) included.

Instead, you need to add it by installing the “Android SDK Platform-tools” pack­age via the Android SDK Manager.

Once you’ve done this, it will be avail­able under {path to Android}/android-sdk/platform-tools/ instead of its old loca­tion under android-sdk/tools/

Sim­ple!

# by Josh on November 9th, 2011 Tags: , ,
|
No Comments »

8 bit PNGs with alpha transparency

To some devel­op­ers, the title of this post might well read “Uni­corns exist! News at 11!”. Excit­ing stuff, but not widely known in my expe­ri­ence. Not that uni­corns exist in my expe­ri­ence. I digress.

The colours below are the palette gen­er­ated with indexed trans­parency (left) vs. true alpha trans­parency (right) in a 256 colour 8 bit PNG by a lovely piece of soft­ware called Fire­works. Let me explain.

I’ve joined a new UI devel­op­ment team this past week that require pretty broad-based browser sup­port for a bunch of sites (i.e. IE6 expe­ri­ence needs to not suck) and their process includes a PNG quan­ti­za­tion step before hit­ting a live envi­ron­ment. This is cool, but the IE6 sup­port neces­si­tates not using alpha. Or so I’m told.

This prompted me to look up some­thing that I dis­cov­ered prob­a­bly around a year ago but never got around to writ­ing it up, nor par­tic­u­larly practicing!

I can’t remem­ber where, exactly, though sus­pect Dave Shea might’ve had a pointer or an arti­cle that pre­sumed knowl­edge of the tech­nique. In the process of writ­ing this arti­cle, I’ve also redis­cov­ered a Site­Point arti­cle on the issue that’s quite helpful.

The bot­tom line is PNG-24 is great but imprac­ti­cal in older browsers for a host of rea­sons. While 8 bit PNG is not with­out its lim­i­ta­tions (c’mon, 256 colours ought to be enough for any­one!), it’s clear that for grace­ful degra­da­tion and mar­ginal improve­ments in file size it’s stil worth considering.

In terms of cre­at­ing images there are a few chal­lenges. First and fore­most, every­one uses Pho­to­shop but Pho­to­shop sucks at save-for-web’ing 8 bit PNGs: you just don’t get the options you need. Fire­works hands you this in spades. I’m no Fire­works pro inso­far as work­flows and just get­ting designs done goes, so typ­i­cally I’ll save for web to a 24bit PNG from Pho­to­shop and then open that in Fire­works to export the alpha 8 bit image.

The Site­point arti­cle linked above sug­gests that [some] quan­tiz­ers will give you the chance to do the same thing, but the issue is if you’re export­ing an 8 bit PNG in the first place you’ve already lost the chance to cre­ate an image with alpha. Most front end devs will want to pre­view things like dithers, colour band­ing, etc., so hand­ing con­trol over to a CLI tool just isn’t going to fly. I’d con­tend that Fire­works is really the only viable solu­tion in that it bal­ances image opti­mi­sa­tion and con­trol. Of course, you’re wel­come to run the PNG Fire­works out­puts through a quan­tiser: it’s already 8 bit so your palette is locked in, and the quan­tiser is unlikely to mess with the alpha if it pur­ports to sup­port this.

The rea­sons are broader than just browser sup­port: in my (lim­ited) test­ing, PNG24 files could eas­ily weigh in at twice the size of their RGBA 8 bit alter­na­tives. On a 500x500px test that gen­er­ated the paletts shown above, file sizes were as follows:

  • 8 bit PNG indexed: 7KB
  • 8 bit PNG trans­parency: 7.5KB
  • 24 bit PNG: 15KB

I’m going to make sure I actu­ally take advan­tage of this fea­ture in the future, as there are clear file­size ben­e­fits to be had as well as sup­port for crappy, dwin­dling browsers. Sorry, IE6.

# by Josh on August 24th, 2011 Tags: , , , , , , ,
|
No Comments »

Quicktime X into Final Cut Pro errors

If you’ve made a screen record­ing using Quick­time X, you’ll likely have dif­fi­culty import­ing it into Final Cut Pro 7 because of its vari­able framerate.

The eas­i­est way to resolve this is to take the file through Com­pres­sor first — ProRes 422 Pro­gres­sive will be great. Frus­trat­ing, but whatever.

# by Josh on June 10th, 2011 Tags: , , ,
|
No Comments »