title: Making Sites More Responsive, Responsibly
url: http://24ways.org/2014/making-sites-more-responsive-responsibly/
hash_url: 47212a397c16b892ee6f76fc0e76d535

<p class="lede">With digital projects we’re used to shifting our thinking to align with our target audience. We may undertake research, create personas, identify key tasks, or observe usage patterns, with our findings helping to refine our ongoing creations. A product’s overall experience can make or break its success, and when it comes to defining these experiences our development choices play a huge role alongside more traditional user-focused activities.</p>

<p>The popularisation of responsive web design is a great example of how we are able to shape the web’s direction through using technology to provide better experiences. If we think back to the move from table-based layouts to <span class="caps">CSS</span>, initially our clients often didn’t know or care about the difference in these approaches, but we did. Responsive design was similar in this respect – momentum grew through the web industry choosing to use an approach that we felt would give a better experience, and which was more future-friendly. </p>

<p>We tend to think of responsive design as a means of displaying content appropriately across a range of devices, but the technology and our implementation of it can facilitate much more. A responsive layout not only helps your content work when the newest smartphone comes out, but it also ensures your layout suitably adapts if a visually impaired user drastically changes the size of the text.</p>

<p class="image"><img src="http://media.24ways.org/2014/jenkinson/24waysgrab_cropped.png" alt="Screenshot of the 24 ways site zoomed at 400%"/> <span class="caption">The 24 ways site at 400% on a Retina MacBook Pro displays a layout more typically used for small screens.</span></p>

<p>When we think more broadly, we realise that our technical choices and approaches to implementation can have knock-on effects for the greater good, and beyond our initial target audiences. We can make our experiences <em>more</em> responsive to people’s needs, enhancing their usability and accessibility along the way.</p>

<h2>Being responsibly responsive</h2>

<p>Of course, when we think about being more responsive, there’s a fine line between creating useful functionality and becoming intrusive and overly complex. In the excellent <a href="http://www.abookapart.com/products/responsible-responsive-design"><em>Responsible Responsive Design</em></a>, Scott Jehl states that:</p>

<blockquote>
<p>A responsible responsive design equally considers the following throughout a project:</p>
<ul>
<li>Usability: The way a website’s user interface is presented to the user, and how that UI responds to browsing conditions and user interactions.</li>
<li>Access: The ability for users of all devices, browsers, and assistive technologies to access and understand a site’s features and content.</li>
<li>Sustainability: The ability for the technology driving a site or application to work for devices that exist today and to continue to be usable and accessible to users, devices, and browsers in the future.</li>
<li>Performance: The speed at which a site’s features and content are perceived to be delivered to the user and the efficiency with which they operate within the user interface.</li>
</ul>
</blockquote>

<p>Scott’s book covers these ideas in a lot more detail than I’ll be able to here (put it on your Christmas list if it’s not there already), but for now let’s think a bit more about our roles as digital creators and the power this gives us.</p>

<p>Our choices around technology and the decisions we have to make can be extremely wide-ranging. Solutions will vary hugely depending on the needs of each project, though we can further explore the concept of making our creations more responsive through the use of humble web technologies.</p>

<h2>The power of the web</h2>

<p>We all know that under the HTML5 umbrella are some great new capabilities, including a number of JavaScript <span class="caps">API</span>s such as geolocation, web audio, the file <span class="caps">API</span> and many more. We often use these to enhance the functionality of our sites and apps, to add in new features, or to facilitate device-specific interactions.</p>

<p>You’ll have seen articles with flashy titles such as “Top 5 JavaScript <span class="caps">API</span>s You’ve Never Heard Of!”, which you’ll probably read, think “That’s quite cool”, yet never use in any real work.</p>

<p>There is great potential for technologies like these to be misused, but there are also great prospects for them to be used well to enhance experiences. Let’s have a look at a few examples you may not have considered.</p>

<h3>Offline first</h3>

<p>When we make websites, many of us follow a process which involves user stories – standardised snippets of context explaining who needs what, and why.</p>

<p><em>“As a student I want to pay online for my course so I don’t have to visit the college in person.”</em></p>

<p><em>“As a retailer I want to generate unique product codes so I can manage my stock.”</em></p>

<p>We very often focus heavily on <strong>what</strong> needs doing, but may not consider carefully <strong>how</strong> it will be done. As in Scott’s list, accessibility is extremely important, not only in terms of providing a great experience to users of assistive technologies, but also to make your creation more accessible in the general sense – including under different conditions.</p>

<p>Offline first is yet another ‘first’ methodology (my personal favourite being ‘tea first’), which encourages us to develop so that connectivity itself is an enhancement – letting users continue with tasks even when they’re offline. Despite the rapid growth in public Wi-Fi, if we consider data costs and connectivity in developing countries, our travel habits with planes, underground trains and roaming (or simply if you live in the UK’s signal-barren East Anglian wilderness as I do), then you’ll realise that connectivity isn’t as ubiquitous as our internet-addled brains would make us believe. Take a scenario that I’m sure we’re all familiar with – the digital conference. Your venue may be in a city served by high-speed networks, but after overloading capacity with a full house of hashtag-hungry attendees, each carrying several devices, then everyone’s likely to be offline after all. Wouldn’t it be better if we could do something like this instead?</p>

<ul>
	<li>Someone visits our conference website.</li>
	<li>On this initial run, some assets may be cached for future use: the conference schedule, the site’s <span class="caps">CSS</span>, photos of the speakers.</li>
	<li>When the attendee revisits the site on the day, the page shell loads up from the cache.</li>
	<li>If we have cached content (our session timetable, speaker photos or anything else), we can load it directly from the cache. We might then try to update this, or get some new content from the internet, but the conference attendee already has a base experience to use.</li>
	<li>If we don’t have something cached already, then we can try grabbing it online.</li>
	<li>If for any reason our requests for new content fail (we’re offline), then we can display a pre-cached error message from the initial load, perhaps providing our users with alternative suggestions from what is cached.</li>
</ul>

<p>There are a number of ways we can make something like this, including using the application cache (AppCache) if you’re that way inclined. However, you may want to look into <a href="https://github.com/slightlyoff/ServiceWorker">service workers</a> instead. There are also some great resources on <a href="http://offlinefirst.org/">Offline First!</a> if you’d like to find out more about this.</p>

<p>Building in offline functionality isn’t necessarily about starting offline first, and it’s also perfectly possible to retrofit sites and apps to catch offline scenarios, but this kind of graceful degradation can end up being more complex than if we’d considered it from the start. By treating connectivity as an enhancement, we can improve the experience and provide better performance than we can when waiting to counter failures. Our websites can respond to connectivity and usage scenarios, on top of adapting how we present our content. Thinking in this way can enhance each point in Scott’s criteria.</p>

<p>As I mentioned, this isn’t necessarily the kind of development choice that our clients will ask us for, but it’s one we may decide is simply the right way to build based on our project, enhancing the experience we provide to people, and making it more responsive to their situation.</p>

<h3>Even more accessible</h3>

<p>We’ve looked at accessibility in terms of broadening when we can interact with a website, but what about how? Our user stories and personas are often of limited use. We refer in very general terms to students, retailers, and sometimes just users. What if we have a student whose needs are very different from another student? Can we make our sites even more usable and accessible through our development choices?</p>

<p>Again using JavaScript to illustrate this concept, we can do a lot more with the ways people interact with our websites, and with the feedback we provide, than simply accepting keyboard, mouse and touch inputs and displaying output on a screen.</p>

<h4>Input</h4>

<p>Ambient light detection is one of those features that looks great in simple demos, but which we struggle to put to practical use. It’s not new – many satnav systems automatically change the contrast for driving at night or in tunnels, and our laptops may alter the screen brightness or keyboard backlighting to better adapt to our surroundings. Using web technologies we can adapt our presentation to be better suited to ambient light levels.</p>

<p>If our device has an appropriate light sensor and runs a browser that supports the <span class="caps">API</span>, we can grab the ambient light in units using <a href="http://www.w3.org/TR/ambient-light/">ambient light events</a>, in JavaScript. We may then change our presentation based on different bandings, perhaps like this:</p>

<pre class="language-javascript"><code>window.addEventListener('devicelight', function(e) {
    var lux = e.value;

    if (lux &lt; 50) {
        //Change things for dim light
    }
    if (lux &gt;= 50 &amp;&amp; lux &lt;= 10000) {
        //Change things for normal light
    }
    if (lux &gt; 10000) {
        //Change things for bright light
    }
});</code></pre>

<p><a href="http://www.sallyjenkinson.co.uk/labs/fauxluminosity/">Live demo</a> (requires light sensor and <a href="http://caniuse.com/#feat=ambient-light">supported browser</a>).</p>

<p>Soon we may also be able to do such detection through <span class="caps">CSS</span>, with <code>light-level</code> being cited in the <a href="http://dev.w3.org/csswg/mediaqueries4/#mf-environment">Media Queries Level 4 specification</a>. If that becomes the case, it’ll probably look something like this:</p>

<pre class="language-css"><code>@media (light-level: dim) {
  /*Change things for dim light*/
}

@media (light-level: normal) {
  /*Change things for normal light*/
}

@media (light-level: washed) {
  /*Change things for bright light*/
}</code></pre>

<p>While we may be quick to dismiss this kind of detection as being a gimmick, it’s important to consider that apps such as <a href="http://www.everywaretechnologies.com/apps/lightdetector">Light Detector</a>, listed on Apple’s accessibility page, provide important context around exactly this functionality.</p>

<blockquote>
	<p>“If you are blind, Light Detector helps you to be more independent in many daily activities. At home, point your iPhone towards the ceiling to understand where the light fixtures are and whether they are switched on. In a room, move the device along the wall to check if there is a window and where it is. You can find out whether the shades are drawn by moving the device up and down.”</p>

	<p><cite><a href="http://www.everywaretechnologies.com/apps/lightdetector">everywaretechnologies.com/apps/lightdetector</a></cite></p>
</blockquote>

<p>Input can be about so much more than what we enter through keyboards. Both an ever increasing amount of available sensors and more <span class="caps">API</span>s being supported by the major browsers will allow us to cater for more scenarios and respond to them accordingly. This can be as complex or simple as you need; for instance, while <code>x-webkit-speech</code> has been deprecated, the <a href="https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html">web speech <span class="caps">API</span></a> is available for a number of browsers, and research into sign language detection is also being performed by organisations such as Microsoft.</p>

<h4>Output</h4>

<p>Web technologies give us some great enhancements around input, allowing us to adapt our experiences accordingly. They also provide us with some nice ways to provide feedback to users.</p>

<p>When we play video games, many of our modern consoles come with the ability to have rumble effects on our controller pads. These are a great example of an enhancement, as they provide a level of feedback that is entirely optional, but which can give a great deal of extra information to the player in the right circumstances, and broaden the scope of our comprehension beyond what we’re seeing and hearing.</p>

<p><a href="http://en.wikipedia.org/wiki/Haptic_technology">Haptic feedback</a> is possible on the web as well. We could use this in any number of responsible applications, such as alerting a user to changes or using different patterns as a communication mechanism. If you find yourself in a pickle, here’s how to print out <span class="caps">SOS</span> in Morse code through the <a href="http://www.w3.org/TR/vibration/">vibration <span class="caps">API</span></a>. The following code indicates the length of vibration in milliseconds, interspersed by pauses in milliseconds.</p>

<pre class="language-javascript"><code>navigator.vibrate([100, 300, 100, 300, 100, 300, 600, 300, 600, 300, 600, 300, 100, 300, 100, 300, 100]);</code></pre>

<p><a href="http://www.sallyjenkinson.co.uk/labs/vibration/">Live demo</a> (requires <a href="http://caniuse.com/#feat=vibration">supported browser</a>)</p>

<h2>With great power…</h2>

<p>What you’ve no doubt come to realise by now is that these are just more examples of progressive enhancement, whose inclusion will provide a better experience if the capabilities are available, but which we should not rely on. This idea isn’t new, but the most important thing to remember, and what I would like you to take away from this article, is that it is up to us to decide to include these kind of approaches within our projects – if we don’t root for them, they probably won’t happen. This is where our professional responsibility comes in.</p>

<p>We won’t necessarily be asked to implement solutions for the scenarios above, but they illustrate how we can help to push the boundaries of experiences. Maybe we’ll have to switch our thinking about how we build, but we can create more usable products for a diverse range of people and usage scenarios through the choices we make around technology. Let’s stop thinking simply in terms of features inside a narrow view of our target users, and work out how we can extend these to cater for a wider set of situations.</p>

<p>When you plan your next digital project, consider the power of the web and the enhancements we can use, and try to make your projects even more responsive and responsible.</p>
