Cindy Krum recently published a must-read primer on the upcoming Mobile-Friendly changes which I highly recommend checking out before proceeding. Got it? Good. With the mad rush to optimize mobile sites prior to April 21st, it can be very easy to sacrifice performance in the process. Lest we forget, Google has mentioned on multiple occasions that website performance is also a factor in search ranking, first in 2010 for desktop sites and again in 2013 for mobile sites.
In this post I'm going to cover a few high-level best practices to keep in mind during your mobile site (re)design efforts. In addition, I suggest you also peruse Google's excellent documentation on mobile-friendly websites.
Measuring your mobile site performance
The first step to improving your mobile performance is to measure where you're starting. There are a number of excellent free and paid resources to do so, but two of my favorites are Google Chrome's built-in Developer Tools and WebPageTest. For the sake of simplicity, I'll be using Chrome Developer Tools in this article.
Not a developer? Don't worry, using the Chrome tools are real easy:
- Open up Chrome (install if necessary)
- Hit the little "hamburger" menu (3 stacked lines) in the top-right corner
- Select More Tools, then Developer Tools
You'll see a nifty screen with lots of juicy info. Most importantly, at the top there's a drop-down with many different mobile and tablet emulators. Pretty cool.
Now, select a device of interest, say Apple iPhone 6. Enter your site address in the address bar, hit enter and voila! You're now seeing your site rendered as an iPhone 6 would see it. Scroll down to the bottom to see some interesting performance stats like total page load time, size of the page, and the total number of requests. Hit the "Network" tab for a particularly helpful waterfall diagram view, as shown below:
Now let's get started...
Optimize those images for mobile
According to the HTTP Archive, images on average account for over 60% of your total page content. Pretty intuitive, images rule the web. Go ahead and check your own page with Chrome Developer Tools and you'll likely see similar numbers. When downloading over relatively slow mobile connections speeds, the impact of large images on your site performance can be even more severe.
While it's always a best practice to optimize your site using lossless and lossy image optimization techniques, there's another consideration for mobile: Should you even be downloading that image to begin with? That big, beautiful 1600px wide "hero" image you use on your desktop site might be completely wasted on the smaller display of a phone or tablet, even if that tablet as a high resolution or "retina" screen.
The solution? Consider loading a smaller image just for your mobile users. Be careful, though; there's a "right" and "wrong" way of doing this.
Quick aside: for this example, and your mobile site in general, make sure you're specifying the viewport meta tag in the head section of your page. Basically, this tells the mobile browser you have a responsive mobile site, and not to try to auto-scale a large desktop site down to mobile resolution (ugly!). Additionally if this tag is not present, you will get different results in your Chrome tests below.
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
The "wrong" way
Responsive design makes heavy use of CSS media queries to style your site differently at the smaller viewport sizes used by mobile devices, so an obvious approach to swap out your images might go something like this:
<!-- DON'T DO THIS --> <style> @media (min-width:376px) { .mobile_image { display: none; } .desktop_image { display: inline; } } @media (max-width:375px) { .mobile_image { display: inline; } .desktop_image { display: none; } } </style> <img src="mobile.png" class="mobile_image" /> <img src="desktop.png" class="desktop_image" />
This code displays one image when the screen resolution is wide, and a different/smaller image when the resolution is smaller.
This looks just fine on the rendered page, but there's a big problem: both images get downloaded! To verify, load this sample in Chrome and you'll see something like this:
Well that's not good; in fact that's even worse! You are wasting time and bandwidth downloading an image that won't even be shown!
The right way
Instead, consider using the background-image
style on a DIV to achieve the same effect, for example:
<!-- DO THIS --> <style> @media (min-width:376px) { .myimage { background-image: url("desktop.png"); width: 700px; height: 550px; } } @media (max-width:375px) { .myimage { background-image: url("mobile.png"); width: 350px; height: 130px; } } </style> <div class="myimage"></div>
Loading in Chrome tools, you'll now see this:
Only the mobile image was loaded... much better! Of course, there is one caveat: to use background-image
with a DIV, you need to supply the image width and height in the CSS for that class. This can be cumbersome for a lot of images, or images that change size frequently, but if your "hero" images are relatively static in nature, strategic use of this technique could make a significant improvement to your mobile site performance.
Takeaway: Where possible, use the CSS media queries and the background-image
style to conditionally render mobile images. This may only make sense for your largest images.
Consider ditching jQuery
What? Did you read that correctly? jQuery is THE library of choice for writing JavaScript, how can you live without it?
jQuery is indeed quite useful, but recall one if its original design goals was to provide a consistent interface that matches the W3C recommended API across wildly diverse browsers with different (and often broken) standards implementations. jQuery let's you avoid writing "if Internet Explorer do this, else do that" code.
BUT, jQuery's unifying interface is much less necessary on mobile. Mobile is dominated by WebKit-derived browsers such as Safari or Chrome, so there are fewer issues to abstract away. And weighing in at a hefty 200 KB, jQuery is still a significant library to download, even with liberal use of caching. Even after you compress and minify jQuery, you are dealing with around 30KB.
But wait, you say; you still want the simplified JavaScript interface jQuery provides? It is pretty nice - so consider Zeptojs instead. While not as fully featured as jQuery, it weighs in at a mere 5 KB in size compressed, roughly 6 times smaller! Since Zepto is largely API compatible with jQuery you shouldn't have to rewrite any code to use it. For most basic JavaScript sites, Zepto is more than sufficient.
Takeaway: Minimize the third party libraries you include, and consider using Zeptojs as an alternative to jQuery if your JavaScript needs are basic.
Review your caching settings
Smart web developers reduce the size of their resources to minimize page load times. Really smart web developers avoid the need to download those resources in the first place. This is where browser caching comes in. If your images, CSS, or JavaScript rarely change, consider caching them. This way your users only download the resource once, and the next time they hit your site the link is already sitting their on their local machine (or phone or tablet), just waiting to be used.
Mobify has a nice primer on setting caching headers, and there are many great free tools that can test your caching settings including the super cool REDbot, WooRank, and our own Zoompf. If you're running an Apache or nginx webserver, consider enabling mod_pagespeed to simplify your caching configuration. If you have a WordPress site, the W3 Total Cache plugin is excellent.
Takeaway: Caching is one of the most effective performance optimizations you can make, and matters more then ever for mobile sites. Review your caching policies and apply caching to your large, infrequently changing libraries and images.
Love animated GIFs? Your browser doesn't!
Animated GIFs have seen quite the resurgence of late, but the format is dated and showing its age. Dating back almost 30 years, animated GIFs are bloated and cumbersome to download, especially when your animated GIF is a short movie clip. Consider using HTML5 video instead of an animated film GIF. All modern browsers support it, and HTML5 videos are typically 10% or less the size of an equivalent animated GIF.
Another option is Imgur. When you upload animated GIFs to Imgur, they will automatically convert the animation into a format they call GIFV. GIFV is essentially just an HTML5 video, but with a significantly optimized size. Imgur manages the hosting of your videos, and optionally serves the file up at GIFV or GIF depending on the capabilities of your users' browser (although most all modern browsers support HTML5 video).
Takeaway: Try and avoid animated GIFs for movie clips or complex animations. Modern video protocols used by HTML5 video and GIFV offer significant performance boosts and reduced download times for your users.
The future: HTTP/2
The web is slowly evolving towards HTTP/2, and not a moment too soon. HTTP/1.1 is over 15 years old and showing signs of its age, especially when it comes to unreliable/intermittent connectivity in mobile devices. HTTP/2 already enjoys widespread browser and server support. While I wouldn't recommend rushing into an HTTP/2 adoption for the April 21st Mobile-Friendly change, future support for this protocol should definitely be on your roadmap. You can read more about HTTP/2 and its future impact on SEO and web performance in my earlier post.
Takeaway: Plan to adopt HTTP/2 on your future roadmap, it's coming!
In closing
Building a responsive, mobile-friendly website is more than tweaking styles and tags to please the Google crawler. There are nuanced, mobile specific considerations that, if ignored, can significantly slow down your mobile site and kill your user experience. Fortunately there are numerous free tools to help you evaluate your mobile site performance, including WebPageTest, Chrome Developer Tools, Google PageSpeed Insights, and Zoompf's Free Report. And of course, make sure to test with Google's own mobile-friendly test tool.
Now...go forth and start optimizing!
Header image by Jane Klein.
How about this tool - feedthebot.com Thanks
It saved my half hour , Thank You @Ofevence
Top free SEO tool, I had forgotten how much I love it!
Great post. !! Sorry for using this blog to resolve our doubts. which is the optimal weight of an image? Thanks for the information.
If it's only the odd hero image it's not so bad, but I don't like using background images as you lose the benefit of alt text (for accessibility as well as SEO), and even the filenames. There are other solutions to optimise images for smaller resolutions. I haven't got around to trying it myself yet but I'd like to give https://adaptive-images.com/ a go.
I agree with getting rid of jQuery if possible. Every bit of code should be reviewed - sometimes I'm amazed at how many extra KB some sites have in JavaScript that doesn't provide any useful functionality.
Hi Alex, I agree. The background-image option is workable for a few major images, but tedious and with limits for the large majority of your images. With that said, the effort is probably only worth it anyway for your large "hero" images (and sprites if you use them), as the differences for small images are likely not worth it.
Depends on the cms we use this can really be a problem. I wont make again my responsive web . It should take into account all the information you have given us. thanks
Very true. I would start small. First, can you modify the templates the CMS uses to be mobile friendly. Then move to the specific content pages.
Great post Billy - lots of detail and awesome resources.
This is a good post to pass off to web developers that need some more details about what exactly they are changing. I learned a few things myself from your code examples.
Well done, sir!
Thanks Patrick. There are a lot of good free tools that can help you like WebPageTest and RedBot. If you want something a little more, we'd be happy to sell you something :-) You can learn more at our website: Zoompf.com
Hi Billy, thanks for this! For us less techie folk it is nice to see an explanation in relatively explainable terms - and very on topic considering the upcoming 21st April. Good tip about the double image downloading for mobile, I am actually going to have to go an check this on my website now!
Cheers
Simon,
Awesome! I wanted to provide a high level discussion of the problems areas to educate. Implementing specific solutions can depend on your technology stack, CMS, internal processes, etc, so its hard to give specific concrete technical advice. However, hopefully this raises awareness and provides a starting point for you to discuss with your team how to address these areas.
Indeed it does Billy - I suppose offering specific solutions would be pretty darn hard with all the variables involved but this does definitely give a bird's eye view to some common issues. Loading speed is so critical not only as a factor in SEO but also in terms of user experience and first impressions!
Great article Billy, simple and easy to understand for (almost) anyone - and this is a must read considering the upcoming G update.
Great information. I also used today the official google mobile testing tool https://www.google.com/webmasters/tools/mobile-friendly/
Great post Billy (I never new the mobile testing part was available in chrome dev tools).
I would highly recommend compressor.io for optimizing images, we used to use others but seem to be getting more compression with these guys. You can see a clear example of a well optimized fast loading website over at seotweaks.com.au who have really specialised within this area, they are sitting at 100/100/100
Chrome dev tools is pretty amazing. Lots of good stuff when you go looking (JS beautifier is a life saver)
Surprisingly, the page I am reading is not mobile friendly, Even moz.com is not mobile friendly
Great informational write up!!
I personally use the google mobile testing tool to check how friendly and fast is my mobile site.https://www.google.com/webmasters/tools/mobile-friendly/
Google webmaster tool also provides information on mobile site issues.
You're right that the 'wrong way' with regard images is wrong, but the 'right way' you're proposing isn't right either.
Moving images from the HTML to CSS isn't the right way to go for a variety of reasons: some images are content and so deserve to be part of the markup, and moving images to CSS doesn't necessarily work well with CMS-generated content.
But more importantly, you should consider sizing your images appropriately for the device's screen size using the picture element, srcset and sizes, instead of loading multiple images and hiding/showing them with media queries.
Plenty of good resources on how to do that including:
And a couple general site performance resources:
John,
You are right. Honestly we should titled it the "better, hacky way for now" instead of "right way".
The smart, scalable, sustainable way to do it are things like the picture element and srcset. These proposals are trying to allow a website to say "I want to display an image here in the page. Here are different versions, formats, sizes, and densities, use the one that makes sense".
Unfortunately, browser support for these is totally fragmented and incomplete. We cannot do the "right way" yet, and even JavaScript pollyfills are not a clean solution (JS library to download, blocking downloads, execution and DOM reflows/repaints, etc).
A simple, though hacky, way to do this now is with CSS, since that provides some conditional logic about the device capabilities. And while there are problems with this approach as well, so many people aren't doing anything at all, even a hacky solution like CSS is a big step forward that many non-technical people can do.
Thanks for the comments
I've been using PictureFill written by Scott Jehl of Filament Group who wrote the 'How we make RWD sites load fast as heck' article recently and not been having any issues.
I try to optimize to the maximum, but i can´t get goog results, i think that the best way is make a especific site for mobile :(
Nice post. Of course mobile friendliness is important for website and google even announced it in Mobilegeddon update. I never seen downfall in ranking of my non mobile friendly websites but i agree on the point that we could get more traffic and business by making our pages mobile friendly.
This is helpful tool for checking mobile friendliness - https://www.google.com/webmasters/tools/mobile-friendly/
Sounds great, its working fine. As per its nature Google will roll out that update before 21st April .
well it is good to have a user friendly websites, and if you will make it fast for mobile user, then what else google want.
Definitely, I never heard before these kind of tips for cellphone optimization. Keep it up
I used the tool today, excelent!! better quality and fast loading
Thank you billy and all of you for sharing your knowledge with us. It is fact more than 70% of users visit sites on their smart phones. It is really a blessing for them if they meet a mobile friendly site. I am working on gaming sites and have a plan to convert them for smart devices, will consider your points billy.
Thanks again.
Hello, nice article I've translated into Farsi and published on the site.
First of all, congrats Moz team on the mobile friendly design. It was long over due and timing of the launch couldn't be more opportune.
Coming to the post, the mobile-friendly design is indeed much more than just a responsive theme/layout.
It's about optimizing all elements to make them load faster and boost users' experiment. The concept of mobile-friendliness is nuanced and it entail tiny details such as the size of font (body text, headings, sub-headings) and even the comment section. Because, each one of these things can potentially affect the user experience.
Personally, I use Genesis framework for all my sites because it makes it easy for me incorporate mobile-friendly elements into my sites.
Great article - A quick question for you - My website www.beastvid.com is okay on the mobile, but the problem is pictures are necessary and the main reason my load times aren't great. Are there any other methods that could be used that will translate well to mobile, without taking away the images which are necessary and important for the site?
congratulations for your post.
Very helpful, lots of useful pointers here. Many thanks.
Definitely every Website should be mobile-friendly. This is one of the most important step when you are doing SEO.
Today more than 50% of the traffic comes from Mobile and Tablets. This Website can also give you an idea about mobile-friendly https://developers.google.com/speed/pagespeed/insi...
Have a nice day!
https://www.mydeswebsite.com
Great Articel,
It's very helpful with me, so i always want to try improve load speed for my website (simicart.com).
I'm particularly interested in the optimum image section for the article. Really is a mistake for the size of the photo is too big (thing I ever made).
Hi!
I did not give too much importance to the optimization for mobile until I read that it greatly influences in the google search results.This is something that worries me now, and since I'm a beginner in these topics, this information is very valuable to me. I'm sorry my English is not as correct as my Spanish thanks :-)
greetings,
Clearly, responsive mobile is important but what can not be is basing a large% of your budget on improving it when you do not have anything definite to PC or Mac. It would be a contradiction.
Great post !!
hello I created my safetyseo website. and i heard that google new algorithm will gonna hit those website whose webstite are not mobile responsive is that really true? and how to check the percentage of how much responsive our website is.
Thanks in Advance :)
This would actually be a good questions for our Q&A forum. :)
Hi Billy,
I am not into development too much. But have been known that mobile websites are equally and more significant in recent times. I have only known method done by back-end. Not got to know something different. Thanks for sharing the info.
Great info Bill! But, I just wonder why Moz website is not responsive? LOL.. Anyways, thanks for the good post! :)
Hello! great post Billy :)
note: As other user said in the comments, Moz.com is not mobile-friendly, but that's not surprising if you analyze semrush.com at the semrush tool (or majestic, moz,...) you will see that all of these pages make the same mistakes they are talking about hehe
Mobile friendly is a buzz word and people are love to talk more and more. Indeed a great post Billy.
Overall people and search trends says "its all about mobile marketing will be the key in 2015". what is your though on predict update of Google on this 25th April? Do you think its a new step to do search engine results more mobile friendly.
I think it is somewhat people should know, like pros and cons! That would be great if you drop your thoughts!
I just installed Google Pagespeed Module on my site, it does most of this automatically. Image compression, minification, combining javascript. It didn't take much work to get a 98/100 speed score after getting it installed. :) Installation is kind of advanced, you have to rebuild your site server through cPanel WHM (or another server based method, you need SSH access) but I think it's worth it.
mod_pagespeed is awesome (assuming you're running Apache or NGing). For those who haven't used it, we wrote a step by step tutorial you may want to check out: Step-by-step Guide to Optimizing your Apache site with mod_pagespeed
Have your website a Mobile-Friendly Test from Google, https://www.google.com/webmasters/tools/mobile-friendly/
Hey Sam!! thank for providing this tool. i checked Moz blog in that tool and in found this -
https://www.google.com/webmasters/tools/mobile-friendly/?url=http%3A%2F%2Fmoz.com%2Fblog%2F
Hi Billy,
First of all, congratulations for your post.
The mobile friendly algorithm starts in all the countries at the same time? I am from Spain and I needo to know if I hace more time to optimize my website.
Hi Sergio, I don't really know much more about Google's rollout plans than what was in their original announcement: https://googlewebmastercentral.blogspot.com/2015/02...
They do mention "This change will affect mobile searches in all languages worldwide and will have a significant impact in our search results.". Perhaps the fine folks at Moz may have better insight into this?
Thanks Billy for this useful post. I'd love to try out this method as soon as I can.
Just wanted to know, should we solely rely on GWT pointed problems related to mobile usability? I mean, if your suggested method points out something that has not been reported on GWT, should we rectify it too?
Thanks,
Umar,
Good question. GWT will help show you mobile usability issues, but it will not flag performance issues with your mobile site. Even Google's PageSpeed Insights will not flag soem things, like oversized background images or lossy image optimizations. You'll need to look at something like Zoompf's free report or WebPageTest.
In short: GWT finds mobile usability issues. Zoompf = finds mobile performance issues. Both effect SERP rank.
Awesome post as we just launched our mobile site last Friday to beat the update in a week or so. Great advice on the background-image style as we are not currently using it. Anything that speeds up the site will be good for our users. Thanks!
I agree with the explanation of the image size will affect the speed of the mobile friendly website, so we have to use the images as needed or should not be too large in size, I tried on my website about smoothies for diabetics with the use of small size images.
Hi,
Billy Hoffman, Really it very good post for mobile-friendly website,you share helpful tips..
Yeah upcoming 21st April google's update their algoritham..and its necessary to make your website Mobile friendly. Thanks for sharing tips.!!
Good article!
As we know, more than half of Internet connections already made via a smartphone, so pages who are prepared for these, will have more profit and will gain traffic to their business. I think that catch and prepare our page to suit any screen format regardless of size is almost mandatory. If you do not adapt, Internet users or customers may have trouble viewing the whole or directly can not view page.
I appreciate your advice to improve our websites to mobile adapting them because it is something that comes some new and do not know how it will be.
Hi Billy,
Excellent post, It is very useful for all blogger and webmaster. I am going to apply your tips at my blog.
Thanks to share this intersting post with all of us.
Awesome, thanks Jyoti glad they were helpful!
That's a very comprehensive guide to improve the page load time Billy :) we can also use tools.pingdom.com to test the speed of page and compare them with their past performances.
Thanks Salman, glad you liked it. Pingdom has some good stuff. I also like WebPageTest and of course, Zoompf's tools :-)
Zoompf's tool is good too :)
Great post and like the idea of moving images to background-images in a div. Although you might loose some responsiveness there.
How about the idea of checking the user agent? On the server side you can identify mobile visitors and based on that display different layouts, stylesheets and images, optimised for mobile visitors. There are many libraries available for that, for example: https://mobiledetect.net/
There is kind of a debate in the web design world right now about whether to have specific mobile/tablet versions, or to have a responsive site. Responsive sites can be easier and supporting multiple versions of the same site can be a pain. Really, it depends on what you are trying to accomplish and what technical resources you have. It's getting easier and easier to build a single responsive site and that's good. But there are common mistakes you can make that impact performance, which I tried to outline above.
Hi Billy,
The article is packed with info. Thanks for sharing; this would be helpful for all the developers who are getting prepared for the mobile update.
Awesome Posting, Thanks For sharing.... I have used your way on my website Rudra Innovative Software.Its very useful for our website & blogs.
Thank you for this - I needed some help getting my site more mobile-friendly :)
¡Really interesting post! Thanks.
Very informatic article. information will really help to optimize website in proper way. Thank you
Wow awesome post Billy.
One thing, I followed your Measuring guide (tools-> developers tools... ), and my sites seems to appear fine on every device.
But, when I test my site on the google's tool (https://www.google.com/webmasters/tools/mobile-fri... I receive a bad score.
Any thoughts?
I have bought a template for my site, which is 10000% responsive, but I still has this. The only thing that I changed in the css is for the responsive AD.
@media screen and (min-width:728px) {.customAd {width:728px;}}
@media screen and (min-width : 728px)and (orientation : portrait) {.widget-header {float:left;clear:both;display:block;}
I believe it's some error to the Mobile-Friendly Test tool, please, correct me if I am wrong
Well Google is the one that decides if your site is meeting their mobile friendly guidelines or not, so I would definitely look into this.
@ NIkola Serafimovski:
Hi,
I hope the below change will fix your issue.
@media screen and (min-width:728px) {
.customAd {
width:100%;
max-width:728px;
}
}
This article is awesome. It gives a more permanent fix. Instead of focusing on just looks or dwelling solely on SEO, it gives a solid fix to both. I so appreciate the examples as well.
Thank you Thank you!
Thank You!!
For sharing valuable information about mobile views for any website...!!!
♥ Ƹ̵̡Ӝ̵̨̄Ʒ..•*´¨`*•.¸♫.•*´¨(♥ˆ◡ˆ) ♥♥♥ (ˆ◡ˆ♥)¨`*•.¸♫.•*´¨`*•..Ƹ̵̡Ӝ̵̨̄Ʒ