Showing posts with label responsive. Show all posts
Showing posts with label responsive. Show all posts

Sunday, February 08, 2015

Responsive Webapp Conclusions

I've spent a few weeks now reading and thinking about whether it makes sense to use responsive web design techniques to build a single page web application (SPA) that works well on mobile and desktop computers. I started with my initial thoughts and reviewed arguments for responsive webapps and against responsive webapps. I haven't done as much reading as I would like and there is still a lot of good stuff out there to read and learn from. But I think I have learned enough to come to some conclusions.

Recommendation

The first step in deciding whether to go responsive or not with a single page web application is to first design the ideal mobile UI and the ideal desktop UI for your app. Obviously phones and desktop computers have different real estate to work with, but when you are designing an ideal UI for your app think also about the different use cases that users on mobile versus desktop computers will have. Don't just think "how do I make this work on small and large screens". For example, consider an email campaign management app. On desktop the UI would likely be optimized for creating new email messages or templates and bulk loading and editing of email lists. On a mobile device the UI would be more geared to checking the status of email campaigns: open rates, bounceback rates, unsubscribes. Design a UI that makes the most sense for your users on both platforms.

Now, if the UI is basically the same except for layout, then Responsive Web Design techniques could be a good fit. You can use media queries to adapt the layout of the app on different devices.

However, you might still not choose to go responsive. Why?

  1. You might want to optimize what is downloaded on mobile devices. Not only to achieve a smaller download size but also to exclude running JavaScript code that would be a performance burden on mobile devices.
  2. You want the flexibility to diverge the UIs in the future. Sure, today, maybe before you even have any users, you think that the ideal mobile and desktop UIs only differ in layout. But apps should evolve based on feedback from users and as they grow new capabilities. (This point might actually be the nail in the coffin for me regarding responsive SPAs. It seems far more pragmatic to start by having separate mobile and desktop UIs.)
Other recommendations
Only two device classes: phone and desktop (or small and large)

There used to be such a clear cut divide between phones and tablets, but any more I don't see much point in developing separate UIs for them. They share a lot of the same considerations:

  • modest computational resources
  • on mobile networks
  • access to sensors like GPS

I think it is sufficient to just have two device classes.

One thing that does seem reasonable is to use responsive web design techniques to have your mobile UI adapt to larger screen area. For example, you could implement the kind of UI like in the iPad Mail app where in portrait you see only the email message but in landscape you see a list of emails in that folder on the left and the email message on the right.

Also, allow the user to switch between the phone and desktop UIs if they desire. A theme running throughout these blog posts is to try to not make any hard assumptions and this is, to me, one of the big advantages of the device class approach. You might think that the user will best be served by the mobile UI but that user may want the desktop UI. (This also dovetails nicely with thinking about different use cases on mobile and desktop: the user may be on a desktop computer but want to use the mobile UI because it is optimized for the kind of task the user currently has in mind.)

Make everything optimized for touch

Whether you go responsive or take the device classes approach, make everything optimized for touch. Size controls so that they can be tapped on and respond to touch events.

An alternative to responsive webapps: Device Classes

This week I spent some time with Boris Smus' article, A non-responsive approach to building cross-device webapps. As the title suggests, Boris presents an alternative to using media queries and responsive design for building webapps that work on a range of devices. It's a good article and I recommend reading it. In this blog post I'll review his arguments and give my thoughts on the matter.

To start with, Boris sees a few problems with Media Queries (or at least, with using just media queries to adapt layout for different screen sizes):

  • All devices get the same assets: the same JavaScript, CSS, images etc. So there is a good chance that devices are downloading a lot more than they would absolutely need to.
  • All devices start with the same DOM. To get the DOM to look one way on one device and look another way on a different device could lead to overly complicated CSS.
  • Not much flexibility to customize the UI for different types of devices. You can do it with a media query approach but if you have a mobile view that is just completely different from a desktop view, you will have duplicate views and the application code has to be careful to handle both views at once, depending on screen size. That is, while creating a custom view for a certain type of device, you have to think about how it will work for all other types of devices.

Smus recommends developing separate UIs for three different device classes:

  1. mobile phones (small screen width + touch)
  2. tablets (large screen width + touch)
  3. desktops (no touch)

He suggests using device width and whether the device is touch enabled to distinguish between these device classes. How reasonable are these criteria?

As one of the commenters mentions, hindsight is 20/20. We live in an era of touchscreen desktop Windows 8 computers, and they don't appear to be going anywhere. We can no longer assume that lack of touch support equals desktop or vice versa. One of my big takeaways from this whole investigation is that all controls should be designed to be touch friendly.

What about the small screen/large screen divide? As I wrote in my previous post, we now have many large phones and small tablets such that the height of a large phone can easily exceed the width of a tablet. I still think a line can be drawn somewhere and I do think that it is useful to design a mobile friendly version of a webapp. But that line is continually moving and blurring.

Okay, now that we have 3 device classes (personally I only see two: mobile and desktop), what does Smus recommend for detecting and serving up these different experiences? Smus compares doing server side and client side detection and comes down on client side detection, mostly because it is feature detection based (more future proof) instead of user agent based. I agree there.

Smus suggests using Device.js (apparently one of his open source projects) to do this client side detection.

He also suggests using a MVC framework and only making separate View classes for the difference device classes. This allows you to get a lot of reuse while also being able to fully tailor the UI for a particular device class.

Overall, I'm impressed with this approach. If your application is best implemented with a different UI on mobile versus desktop, I think this is probably the best approach. Responsive Web Design seems to be a good fit only when the UI is basically the same on mobile and desktop with only the layout needing to be a little different. For example, at Walker Information, we have a survey application. On mobile and on desktop, the essential UI is the same, with only layout differing. Each page has a list of questions and controls for providing answers, with Back and Next buttons to navigate through the survey. This is a good candidate for being designed responsively. As a counter example, consider something like a webapp for MailChimp. On desktop it might be optimized for creating emails and setting up campaigns whereas on mobile the UI might be quite different and be focused on monitoring open rates, bounceback rates, etc. In this case, having two completely different apps would be a better fit.

There are some downsides with this separate app for device classes approach:

  • If the device class is part of the URL then bookmarks, shared links would include it as part of the URL. It would be nice to have canonical URLs.
  • Separate views for the device classes is extra work and has its own maintenance overhead
  • Doesn't respond to orientation changes or browser resizing
    • However, it would be possible to combine both approaches. You might create a separate view for the mobile device class that itself uses media queries to adjust the UI between phone-like sizes and tablet-like sizes.

On a closing note, there is one other thing I like about Smus' approach. He recommends having links in the app to the different device classes. This way if you are on a mobile phone and really want the desktop view, you can get to it. I think this is in line with the thinking from the last blog post that challenges the consensual hallucination that we as web developers tend to participate in. Our assumption about what is mobile, what is a desktop computer are being challenged all the time. It would be good to make fewer assumptions. Letting a user switch to a non-default device class, to me, fits in with that line of thinking. We only have a limited understanding of the kinds of devices that exist today. Hopefully the devices that arrive in the future will surprise us and challenge our assumptions. And hopefully our webapps will be ready.

Additional Resources:

  • Really liked this post by Brad Frost that Smus links to. He makes the point that while media queries are great, the most important thing to optimize on mobile is performance.

Sunday, January 18, 2015

Researching Responsive Webapps

In a previous post I wrote about my initial thoughts regarding responsive Single Page Applications (SPAs). I've now done a bit of digging to find out what other folks think about this topic.

Among the blog posts I read I found Jason Grigsby's series of blog posts Responsive Design for Apps especially interesting.

Consensual Hallucination

In the first blog post in this series, Jason makes the case that web developers and web UI framework authors have been participating in a consensual hallucination regarding what phones and tablets and desktop computers are limited to, just as we once assumed desktop browsers were 960 pixels wide. Web UI frameworks tend to have a library of mobile widgets (e.g, jQuery Mobile) and a separate library of desktop widgets (e.g. jQuery UI). The reasoning given by framework authors is that phones and tablets and desktops are fundamentally different platforms. But what are these fundamental differences? A cellular radio? The answer isn't clear and Jason is dubious that a good answer exists.

Jason looks at the size of phones and tablets and points out that the height of the larger phones out there easily exceeds the width of the smaller tablets available. His article was published in early 2013 and since then the gap has only narrowed. In fact Jason at one point says

The small gaps that exist are either things that seem inevitable (high-dpi on large screens) or are so small to be inconsequential (does it matter that we don't have six inch displays?).

And of course, we now have 6-inch phones and 6-inch tablets.

There's no clear line between phones and tablets, but what about desktops? We used to be able to assume that touch was a fundamentally distinct mode of interaction on mobile devices. However, Windows 8 and all of the touch screen desktop and laptop products that are built for it obliterates that assumption. He points to research to suggest that touchscreen desktops are not a fad. I've yet to have a chance to play with a Windows 8 touchscreen device myself but I agree. I have to believe that eventually Apple will have to catch up too.

One of the key takeaways for me from this article is that every application should be designed for touch interaction. Primarily this means making targets big enough to be easily tapped on with fingers. Because of Fitts's Law, desktop users using a mouse will also benefit because these larger targets are easier to hit.

Making desktop app responsive

In Jason's second post he looks at a typical desktop app and tries to reimagine it as a responsive web app.

One of the problems he ran into is that if you take a desktop app design and try to make it responsive, you kind of run into a brick wall. He starts making progress when he takes a mobile first strategy. He designs a version of the web app that is optimized for mobile.

Once he has an optimized mobile design, he then looks at how it maps to the desktop app and finds that it maps pretty well. That's important for a responsive web app; each screen in the mobile design needs to be able to map to a corresponding screen in the desktop design. If there isn't a mapping, that is, if the mobile design is not just a different layout compared to the desktop design, then responsive web design probably won't work.

Finally, he takes another look at the desktop design and rethinks it in terms of the mobile design. This is also an important step in evaluating if responsive web design is feasible. For the mobile design he had to compromise in some places and display less information than on the desktop design. So its important to step back and look at if these mobile design components can be used in the desktop design.

Desktop and mobile design patterns

In the third part of the Jason's series Jason looks at how desktop operating systems have been incorporating mobile design ideas. In particular he looks at Apple's Mail app on iPhone, iPad and Mac OS X.

The iPhone Mail app uses a nested doll design pattern: moving froma list of items to greater detail or sub-lists of that item. On the iPad, we see a slightly different pattern, what has been called the bento box pattern: the list of email messages is displayed on the same screen as the detail. The iPhone and iPad app actually share views (for example, mail accounts and folders listing screens).

On Mac OS X, the Mail app there shares a lot of similar design elements although it does have a different look. One could definitely imagine there being a single Mail app that runs across all Apple devices and that adapts to the available screen real estate.

To me it is a little bit of stacking the deck to use the Mail app. Because information in the Mail app is arranged hierarchically (mail accounts list, folders list, messages list), it is not too hard to design a responsive Mail app. But not all apps are so simple. Word processing apps tend to have a main content area and several controls for affecting layout and formatting. A mobile word processing app design would be quite a different design, not likely to share much with its desktop counterpart.

Also, Jason only looks at views that display lists of accounts and emails and the views that display the email itself. That is, he only considers the views related to reading email. The desktop Mail app includes formatting options and stationary options when composing email, which would take up too much real estate on mobile. This is because on mobile users are typically more interested in reading and filing and flagging and deleting email. On mobile users only need to be able to write short responses, typically. On desktop the email composing needs are very different.

Nevertheless, I think his conclusion that

responsiveness for apps is inevitable

is mostly true. Responsive web design can be a good fit for some apps and even apps that are better served by different UI designs on mobile and desktop will benefit from responsive design techniques on mobile (for example a mobile UI that responds to more real estate on a tablet versus a phone).

Conclusions

I find Jason's arguments compelling. The idea that phones are fundamentally different from tablets and desktops and so require different UI frameworks and separate apps is undermined by the evidence that not much actually separates these different devices in terms of technical capability.

However, one thing that I think is missing a little from the discussion is how these different devices are used and what they are used for. Yes, technically, there isn't much difference between phones and tablets and desktops except screen size. On the other hand, users on mobile devices may have different tasks in mind that they want to accomplish versus users on desktop devices. As I mentioned above regarding the Mail app example, mobile users mostly want to read and deal with email by flagging, filing, deleting etc. Composing longer or more format heavy emails are saved for when the user is at a desktop computer. Now, this isn't a big difference in goals for mobile and desktop users for this particular app, but for certain apps mobile users may have very different goals from desktop users. This needs to be kept in mind when designing optimal desktop and mobile UIs. I'll expand on this a bit in future posts, but to me this is one of the most important reasons why you might want separate mobile and desktop apps.

Saturday, December 20, 2014

Initial thoughts on Responsive Single Page Applications

Is it feasible to build a responsive, mobile-first Single Page Application (SPA)? Here are my initial thoughts on the feasibility and challenges of building a responsive SPA. I plan to do more research in the coming weeks to hopefully answer this question more completely.

I was recently working on a mobile version of FuelMyRoute. I started by using jQuery Mobile and Backbone, but I found trying to use jQuery Mobile as a UI framework frustrating so I decided to give the Bootstrap CSS framework a try. I was able to convert my code over to Bootstrap fairly easily, but I started reading about and thinking about the responsive features of Bootstrap. This got me to thinking maybe I could make a responsive Single Page Application, one website that would work well on mobile devices and on desktop computers.

The benefits are pretty obvious I think. I don't relish the idea of maintaining two separate web applications. Especially when a lot of the non-UI code would be very similar. I could get a mobile site for my application while at the same time updating and modernizing the existing desktop site. That's a huge win!

I should probably define what I mean by responsive SPA. First of all, a Single Page Application is a web application where there is only an initial full page load. From that point forward AJAX is used to interact with the server to fetch data (e.g. get new mail) or to perform server side actions (e.g. send an email). The DOM is manipulated as appropriate in response to user actions and requested information. A responsive SPA is one where the UI of the SPA changes based on the size of the viewport, so that it is more appropriate/usable on smaller viewports but also can adapt and take advantage of more screen space on larger viewports. Responsive to me means also taking a mobile-first approach to web application development, where the mobile phone/small tablet use case is given primary (or at least equal) consideration.

But, I don't really see or hear much about responsive SPAs. I'm talking strictly about web applications, not web sites. If you are building, for example, a blog, then there is a lot of advice and support for making it responsive. However, for applications, it's different. The received wisdom is that it is better to have two different sites, one for mobile and one for desktop. Why? This is a question I want to answer along with the following:

  • What are the problems/tradeoffs that are encountered when making a responsive SPA?
  • Is it possible to use only CSS, only media queries to switch between different layouts for mobile and desktop usage? Or would it be necessary to have the JavaScript code be aware of whether the application is in mobile or desktop mode? (Ideally the responsiveness would be implemented in CSS only)

In this blog post I cover my initial thoughts about how a responsive SPA could work and what the challenges are likely to be.

Responsive Mobile UI Patterns

How would this work in practice? In this section I'll go over a couple of common mobile UI patterns and how they would adapt to a larger viewport.

Separate "pages" (mobile) vs in-page controls (desktop)

Sometimes the ideal view on mobile is very different from the ideal view on desktop. A common pattern here is that on desktop you have enough room to display all controls on the same screen, but on mobile you might want a separate full page view for certain actions. For example, imagine an airplane flight search application. On desktop you could have the fields for departing city and arriving city and dates on one page and display the results under those controls. On mobile, there isn't enough room for this so you would rather have a separate full page view for specifying search criteria.

In some ways, this is the least ideal situation. It is always better to be able to reuse the same controls and just style them differently using media queries. However, we must anticipate that this might not always be possible and think about what we could do in that situation.

To accomplish this, we could simply include the mobile full page alternate view in the page, hidden unless the width of the page is wide enough. By default, the mobile view is hidden.

#mobile {
    display:none;
    background-color: #fff;
    z-index:1000;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}
@media only screen and (max-width: 480px) {
    .desktop-only {
        display: none;
    }
    #mobile {
        display: block;
    }
}

I created a very simple demo of this concept using the airplane ticket search example. In practice, you would want to have your application code add and remove CSS classes from a top level element to drive hiding and showing different views, but I've left that sort of thing out.

This "separate page" view could possible have a use on the desktop layout. You might have a situation where not all controls fit on the desktop layout so the same view to show all controls can be used on mobile and desktop. On mobile it might be styled as a full page view, whereas on desktop it could be styled as a modal popup.

Data binding is a little complicated in such a situation. Ideally, if the user changes the size of the browser window then switching from "mobile" to "desktop" or vice versa should be seamless from a user input perspective. Using the airplane ticket search example, if I am in the "mobile" view and I type in a Departing from city and then decide to expand my browser and get the "desktop" view, then ideally the Departing from control in the "desktop" layout should be populated with what I had typed on the "mobile" view. This means that I need to bind to the keypress event and update my model as each key is typed in Departing from and keep the "mobile" and "desktop" Departing from fields in sync.

Another challenge with this approach is that you, obviously, have two different views that have to be maintained. Arguably, this is one of the benefits of adopting MVC in the first place: your models are independent of views and models can have more than one view. However, it is still something extra that has to be maintained. It is probably better than having two separate sites though.

List and detail views on separate pages (mobile) vs both on the same page (desktop)

A common pattern with mobile apps is that you have a view(s) that display lists of data and tapping on a list item takes you to a view that displays details for that item. Examples include inbox listing/email detail and contact listing/contact details.

On desktop however there is enough space to show both the list and the detail, typically with the list on the left hand side and the detail view on the right. For example, an email client.

Media queries can be used to achieve both of these layouts. One nice thing here is that the same views are used on mobile and on desktop. Its just on mobile they are separate "pages" and on desktop they are all on one page.

How would you achieve this with media queries? I won't flesh out an entire example here, but I will outline how it would be done. The key I think is to have your SPA router add/remove CSS classes to a root element of the DOM. When the "list" class is added to the root element, the mobile media query will make just the list view visible, hiding the detail view. For desktop, there is no additional work needed. Likewise, when transitioning to the detail route, the "list" class is removed from the root element and a "detail" class is added. The mobile media query would then hide the list view and make the detail view visible. On desktop, the presence of the "detail" class on the root element might cause the currently selected item to be highlighted.

One challenge that this approach highlights (and this was true of the "separate view" UI pattern above) is that although on mobile the user is seeing only one view at a time, those other views are still there. For example, in an email client app, only the detail view may be visible, but the list view is still there and still responding to model updates. So for example, if you have a periodic check for new email, then the list view is updating to display new email received. This is more of a problem for mobile where off screen updates may cause performance to drag. On desktop the presence of alternate views that aren't on screen is unlikely to cause much of a problem.

Challenges with doing responsive SPA

Some of these challenges were mentioned above. Here I'll summarize them and also discuss how to address some of them. Not having experience developing a responsive SPA, this is mostly speculation about what I anticipate would be challenges building one.

Sizing of controls

It's possible to use media queries to size controls differently. You could for example make buttons large, more "tap friendly" on mobile screens and smaller on desktop screens.

However, one would have to assume that small screens are tapped on and large screens are clicked on. And that assumption isn't valid in a lot of cases. For example, a mobile phone might have a stylus that is able to make very precise touches. As another example, there are now several Windows 8 devices, some that are tablet/laptop hybrids, that are basically desktop devices but allow for touch interaction.

So I think a reasonable approach is to just size all controls for tapping. The tradeoff is that on desktop the controls are going to be "fatter" than necessary, meaning you won't be able to fit as many controls on the same page, but I don't think there is any reasonable alternative unless you want to aggravate uses with large touch screens.

Also, the fact that you can't have as many controls on a desktop view is not necessarily a bad thing. It will lead to a simplification of the UI, which will probably end up being easier to use.

Off screen view updates on mobile

I mentioned this one above. What can be done? For one, I think some testing and validation that this causes an issue is necessary first. Are DOM updates that are off screen as intensive as on screen ones for the browser to handle? Maybe, hopefully, not. I think it can very much depend on the application and might only affect certain views but not others.

If it becomes a problem I think one thing that could be done is to delay re-rendering the view if the view is off screen. Whenever it is ready to be brought back on screen the view could first be fully re-rendered. The problem here is that JS code now needs to know if the app is in "mobile" mode or "desktop" mode and so far I've been trying to keep the differences purely in CSS media queries.

Duplicate UIs

This one is mentioned above too. This is most applicable when the "mobile" version of the app needs a completely different view from the "desktop" version.

To mitigate this, first, obviously, try to use the same views for "mobile" and "desktop" and simply have them laid out differently.

Also it should be said that the duplication of effort and maintenance is probably not nearly so much as having two separate sites.

Also as mentioned above, there is also the data binding consideration: you'll want to keep the "mobile" and "desktop" views in sync at all times because the user could at any time transition from one to the other. In practice I think this requires only a little extra effort. See the discussion on listening for keypress events above.

Conclusion

Well that's it for my initial thoughts. I hope to investigate this further and try some of these techniques out.