By Luca Passani, CTO @ScientiaMobile

Online Image Optimizer (OIO) is a public utility site: no account, no watermarks, no upsell. It compresses, converts, resizes, crops, rotates, flips, darkens, watermarks and captions images, handles batches of up to twenty, and converts PDFs to images and back.

We didn’t launch it because of our good heart (well, maybe a little bit). We launched it to showcase our flagship products: WURFL.js Business Edition and ImageEngine (and ImageEngine Kube). 

When it comes to WURFL, OIO acts as a reference implementation. Responsive Web Design (RWD) is the way you build cross-platform (web, mobile, tablets and apps) services nowadays.

 In fact, developers don’t think in terms of a mobile web separate from the web anymore. But believe it or not, there was a time when telling web and mobile traffic apart was the only way one could meaningfully support both user experiences (look up WAP and mDot for details). At the time, using WURFL (i.e., Device Detection) to separate “user agents” was a requirement before you could serve tailored user experiences to both web and mobile visitors.

All of that went gradually away (or even not so gradually if I have to be perfectly honest) in 2010, when the introduction of conditional CSS definitions (Media Queries) allowed websites that turned themselves into a column on smartphones (this is not a 100% accurate way to describe RWD, but you get the spirit).

Yet, device detection can still play a role in customizing the functionality and the user-experience in ways that traditional JavaScript-only approaches — i.e. feature detection — simply cannot.

Every device-dependent decision in OIO is visible from the outside, and every code sample below is taken from it.

The site is a Vue 3 application served through ImageEngine, with per-task entry points generated from a registry: PDF to JPG, a responsive image generator, HEIC to JPG, bulk compression, JPG to WebP, EXIF removal, PNG to WebP, email-sized photos, resize, MP4 to GIF and around fifteen more, each with an illustrated walkthrough.

The interesting part is that OIO is not a demo built on top of something else. Drop a JPG on the page and take back a WebP a third of the size. That is ImageEngine doing the work — the same compression, format conversion, resize and crop our customers get in production. They consume it as a URL in front of their origin. OIO visitors consume it as a drop zone.

Enter WURFL.js

Integration is a script tag:

const wurfljs = document.createElement("script")
wurfljs.setAttribute("src", "//wjs.wurflcloud.com/wurfl.js")
document.head.appendChild(wurfljs)Code language: JavaScript (javascript)

This is not a client-side parser. The browser issues a request; ScientiaMobile’s servers run the full WURFL engine against that request’s headers; the response is a resolved object. For a Pixel 8 Pro:

WURFL = {
  complete_device_name: "Google Pixel 8 Pro",
  form_factor: "Smartphone",
  is_smartphone: true, is_tablet: false, is_full_desktop: false,
  physical_screen_height: 156, physical_screen_width: 70,
  resolution_height: 2992, resolution_width: 1344,
  pointing_method: "touchscreen"
  // 26 capabilities in total
}Code language: JavaScript (javascript)

1.9 KB gzipped. Two fields deserve attention.

physical_screen_width: 70 is millimetres. No browser API exposes this. window.screen reports pixels, and a pixel has not corresponded to a fixed physical size since 2010.

form_factor takes one of eight values — Desktop, Tablet, Smartphone, Feature Phone, Smart-TV, Robot, Other non-Mobile, Other Mobile. This is deliberately coarse. The question is what class of device this is, which has eight sensible answers and no personalization implications.

Two notes on accuracy. Apple’s iOS user-agent strings and Google’s frozen Chrome user agent both require additional work — in Chrome’s case an HTTP negotiation for User-Agent Client Hints. WURFL.js performs that negotiation on your behalf and returns the same resolved object either way.

Multiserving OIO’s Drop Zone

Note: multiserving means serving different markup from the same URL depending on the device. It’s an old mobile-web term, and young readers — the RWD-native ones — probably don’t know it. If you’re one of them, now you do.

The widget that lets users upload files is the best possible example. Users have different ways to create files (or reach for them) on a desktop or on a mobile device.

Figure: Drop zone (Desktop experience)

Figure: Drop zone (Smartphone experience)

The drop zone describes the correct gesture. “Drag your images here” is wrong on a phone; there is nothing to drag from.

<span v-show="!files.length && !myWURFLData.isMobile">{{ words.dropzone }}</span>
<span v-show="!files.length && myWURFLData.isMobile">{{ says('dropzone.mobileHeadline') }}</span>Code language: HTML, XML (xml)

Clipboard paste appears only where a clipboard exists. Advertising ⌘+V on a phone is not graceful degradation; it is a dead end.

<template v-if="myWURFLData.isDesktop && accepted.images">
  {{ t('dropzone.paste') }} <b>{{ t('dropzone.pasteKeys') }}</b>
</template>Code language: HTML, XML (xml)

Other examples of multiserving

Instructions invert by form factor. Desktop gets the three-step guide expanded. On a 360-pixel screen, an expanded list pushes the only control that matters below the fold, so it collapses to a link.

The <picture> markup tutorial is hidden on phones. The responsive image generator prints markup for pasting into a codebase. That is desktop work.

Thumbnail preview has three outcomes, not two. Desktop hovers. Tablet presses and holds. Phone does neither, because the screen is barely larger than the preview and press-and-hold collides with scrolling.

configurePeek({
	hover: !!myWURFLData.value.isDesktop,
	hold:  !!myWURFLData.value.isTablet,
})Code language: HTML, XML (xml)

@media (hover: hover) yields two outcomes and misclassifies the iPad, which reports a Macintosh user agent in desktop mode and supports neither gesture well. CSS has no query for “this is a tablet”.

The delivery side

The same knowledge operates below the application. Serving the site through ImageEngine, a 2.9 MB master returns as a 28 KB AVIF to a Google Pixel and a 145 KB AVIF to a desktop — same URL, different payload, no markup changes.

Accept: image/avif tells you the browser decodes AVIF. It does not tell you the device wants 1344 pixels rather than 2560. That second judgment requires knowing the device.

Where the detection runs

Online Image Optimizer is a static SPA on a CDN with no origin request to attach a decision to, so WURFL.js is the right fit. An application with a server in the request path — Django, Rails, Spring, Node — would use WURFL InFuze or OnSite instead and render the correct page on the first response, with no repaint.

The distinction that matters

The criticism leveled at “user-agent sniffing” — yes, this is the expression used by detractors — over the past fifteen years was largely fair. A regex written in 2011, still shipping in 2019, still concluding that a tablet is not a mobile device because its user agent does not contain the string Mobile, deserved every word of it.

That is guessing, not detection. The difference is a continuously maintained device database, an engine that resolves headers rather than pattern-matching them, and a vendor whose job is keeping both current as new devices ship on a daily basis.

A media query reports a 390-pixel viewport. It cannot report a 70-millimeter screen. Feature detection reports that hover is supported. It cannot report that this is an iPad, where hover is nominally available and practically useless.

These are not edge cases. They are the difference between a site that functions on a phone and one built for it.

The site is onlineimageoptimizer.com, free and account-free, and the source of every snippet above. Product details: WURFL.js, ImageEngine. 

Here is a list of all tasks OIO currently supports.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Want access to the latest mobile device trends?

Download the Mobile Overview Report.

>