Speed Up Mobile Apps and Websites with AMP

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: Find out what AMP is and how you can optimize your website for mobile devices with AMP.

By Sai Sarath Chandra, Alibaba Cloud Tech Share Author and Alibaba Cloud MVP

The Internet is now everywhere. In this "digital information age”, information transfer is instant and ubiquitous, making its way even to the most conservative industries such as finance and healthcare. Thanks to the innovations in hardware, devices are also getting smaller, which translates to increased mobility. In fact, mobile technology has overtaken (or at least on par with) many traditional solutions.

According to Statista, "The number of mobile phone users in the world is expected to pass the five billion mark by 2019. In 2016, an estimated 62.9 percent of the population worldwide already owned a mobile phone. The mobile phone penetration is forecasted to continue to grow, rounding up to 67 percent by 2019. China was predicted to have just over 1.4 billion mobile connections in 2017, while India was forecast to reach over one billion. By 2019, China is expected to reach almost 1.5 billion mobile connections and India almost 1.1 billion."

These numbers can be summarized as follows:

  • More than half of the world's population use smartphones.
  • Almost two-thirds of the world’s population have mobile phones.
  • More than half of the world’s web traffic originate from mobile phones.

1

New Approach to Reducing Page Load Time

Despite the rapid growth in mobile technologies, there was still an unresolved issue – page load time. With fancy UX & UI designs, webpages are loaded with lots of custom JavaScript, CSS and HTML codes to provide best user experience. However, this affects the page load time. A workaround for this problem is to cache these pages, but caching doesn't help first-time access.

Speed is an integral part of designing web pages. Data from KISSmetrics shows that “about 40% of people will abandon a web page that takes more than 3 seconds to load.” Furthermore, if an online shopping site is making $100,000 per day, a 1-second page delay could potentially cost you $2.5 million in lost sales every year. To solve this issue, there is an interesting open source project called "AMP", which stands for Accelerated Mobile Pages.

2

Accelerated Mobile Pages is an open source initiative project designed to optimize and speed up mobile pages. It’s like taking a page that’s already mobile friendly and making it load quicker by stripping it down to the basics. Not all mobile websites are using AMP, but it is rapidly gaining momentum.

"Accelerated Mobile Pages (AMP) is an open source initiative project/platform aimed at helping publishers improve the speed and readability of their mobile content pages,” quoted from the official AMP website.

Faster Mobile Pages + Readable Content = Better User Experience

How does AMP provide faster and smoother page experience? In the simplest terms, AMP framework achieves this by placing restrictions while developing the mobile pages.
However, AMP is not for everyone. You should take note of the below limitations when considering AMP for your applications:

  • No JavaScript will be allowed other than an off-the-shelf AMP library.
  • Images will only load when you scroll down to them (lazy load functionality).
  • A streamlined version of your CSS will be required.

If your site is mostly serving static content, then you can directly leverage the benefits of the AMP framework. There are some workarounds where you can also use AMP for dynamic content. But if you are thinking about a site that has dynamic HTML, then AMP might not be suitable for you.

Benefits of AMP

Reduced Bounce Rate:

The correlation between site speed, page views & search engine rankings is very significant. When a web page loads very quickly, users will view more pages on the site, reducing bounce rate. In reality, well-built AMP pages typically rank higher than non-AMP pages in search engines.

Increased Mobile Browser Visibility:

Many search engines have started showing AMP powered pages in their organic search results, which increases the credibility of the site and improved click through-rate for AMP pages. In turn, search engine users will then begin to look specifically for AMP plugin pages, since these pages load up quicker than the typical mobile pages.

Flexible Ad Support:

Websites that mainly depend on ads for revenue can benefit by integrating AMP. That’s because not all HTML code tags are executed; you only use a streamlined version of CSS, and JavaScript is out of the question (mostly). It’s also approximately six times lighter in terms of code. AMP also supports most leading advertising platforms, which means you don't have to worry about compatibility with your ad provider.

Basic Building Blocks of AMP

AMP framework is designed to be simple for webmasters & developers. There are just 3 High Level building blocks.

  • AMP HTML: A subset of HTML, this mark-up language has some custom tags and properties and many restrictions. But if you are familiar with regular HTML, you should not have difficulty adapting existing pages to AMP HTML. For more details on how it differs from basic HTML, check out AMP Project’s list of required mark-up that your AMP HTML page “must” have.
  • AMP JS: A JavaScript framework for mobile pages. For the most part, it manages resource handling and asynchronous loading. It should be noted that third-party JavaScript is not permitted with AMP.
  • AMP Cache: An optional Content Delivery Network, it will take your AMP-enabled pages, cache them and automatically make some performance optimizations.

How to Integrate AMP into Existing Sites

If you are using a CMS like WordPress, the AMP plugin does most of the work for you. But if you are using other CMS, or you have created a custom CMS for yourself, you will need to take care of creating the AMP pages by yourself.

3

If you are beginner, you will be using the basic setup like the one above. You are recommended to set up both traditional HTML pages alongside AMP Pages to get comfortable with AMP. Make sure the AMP Pages are served with via a different URL. Once you are comfortable, you can create AMP pages as your main site.

AMP doesn't permit custom JavaScript and custom forms so you may not have lead forms. You might need to rewrite the site template to accommodate these restrictions. AMP requires CSS to be inline and the total size should be less than 50 KB. Custom fonts should be loaded using a special amp-font extension.

Integrating AMP with Analytics

To prevent multiple analytics tracking from slowing down a site, AMP implemented the philosophy of “measure once, report to many.” There are two paths to enable analytics functionality with AMP for your website:

  • The Amp-Pixel Element: This is a simple tag that can be used to count page views as a typical tracking pixel would, using a GET request. There are a number of variables that can be passed through it, such as DOCUMENT_REFERRER and Title.
  • The Amp-Analytics Extended Component: This is a little bit more advanced than the amp-pixel. It is likely what you’ll use to implement analytics on your site because it allows for a greater level of configuration for analytics interactions.

If you aren’t trying to get Google Analytics working, amp-analytics is the way to go. You will need to add the necessary JavaScript library in the

and then configure it via some JSON mark-up in the body section of your page.

What can I do If I want to inject/refer my legacy pages?

Injecting/Referring Legacy Pages into AMP Pages

AMP provides a way to inject your Legacy pages (non-amp pages) into AMP Pages by using iframes, but you have to eye-out for the restrictions that come along the way. Iframes are given very low priority and should be presented towards the end of a page or at least after 75% of the page. The purpose of doing this is so that iframe will not slow down the page load speed, which will in turn affect the user experience.

Note: the Global DOM will not be available in the iframe. At the time of writing this article, you can't make the custom JavaScript inside the iframe to access the Global DOM of the AMP Pages

Attractive UI and UX Options with AMP

Most people think with these restrictions, we need to compromise on the UI/UX Design. On the contrary, AMP HTML provides a lot of components that helps make your website attractive. The list is too long and I probably can't go through every one of it, but all the components are classified into three types:

  • Built-In : Components that are included in the base library.
  • Extended : Extensions to the base library that must be explicitly included in the document as custom elements.
  • Experimental : Components that are released but are not yet ready for wide use.

In addition to the classification by type, the amp components can be categorized into:

  • Ads and analytics
  • Dynamic content
  • Layout
  • Media
  • Presentation
  • Social

If you want to learn more about this, you can refer to the official AMP documentation.

In my opinion, AMP provides enough toolkit for developers to create beautiful looking blogs and websites. AMP CSS mandates 50 KB of inline CSS, which actually plenty for most websites. In addition, optimizing and compressing the CSS with scss will give more room for developers to accommodate more CSS attributes.

However, due to this restriction, we will not be using additional CSS attributes. By doing so, we essentially prevent any sudden surprise and reduce the testing time as well as bugs. All changes made to the page will only be limited to that particular page, making sure that changes are not affecting the other pages.

Third-party JavaScript software typically use synchronous JS loading. Most of them would also consist of document.write to write more sync scripts. But this can slow your page down. For example, if you have five ads on your page, and each of them cause three synchronous loads, each with a 1 second latency connection, you’re in 15 seconds of load time just for JS loading.

AMP pages allow third-party JavaScript but only in sandboxed iframes. By restricting them to iframes, they can’t block the execution of the main page. Even if they trigger multiple style re-calculations, their tiny iframes have very little Document Object Models (DOMs).
The time it takes to do style-recalculations and layouts are restricted by DOM size, so the iframe recalculations are very fast compared to recalculating styles and layout for the page.

Creating a Functional Mobile Website with AMP

Previously, we discussed that AMP is very good for static content since they do not involve any custom JavaScript. However, it turns out that this amazing technology can also be used for e-commerce websites to increase the speed of the website. Hopefully, this will translate into increased click through rate and sales.

Going further, we are going to design an e-commerce application that is optimized for mobile devices. We will be leveraging the benefits of AMP to provide a responsive, fast-loading and cache-enabled e-commerce store. The e-commerce mobile application will be built in 3 steps, each presented as an individual tutorial.

1. Basic Building Blocks and UI Using AMP

In this section we will be discussing about creating the user interface of The E-Commerce store. We will be using AMP components to achieve this. Here we will be a deep diving in to the AMP HTML Components & AMP JS

2. Creating Backend with Alibaba Cloud ApsaraDB for MongoDB

We will be exploring the ApsaraDB for MongoDB product in depth. Offered by Alibaba Cloud, ApsaraDB for MongoDB will be the backend for our application. Due to certain limitations, we will be creating a small architectural solution to make the application work with Mongo DB. Creating an architectural solution is not as scary as it sounds, it is very easy if you can follow along with the article.

3. Integrating the Entire Application with Alibaba Cloud ApsaraDB for MongoDB

In this part, we will be integrating the UI along with the backend created on ApsaraDB for MongoDB. This section is very important as we are going to create the core functionality by integrating the application. We will also talk about the overall functionality of our application.

Stay tuned to the Alibaba Cloud Blog for these tutorials!

相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
安全 网络协议 应用服务中间件
Setting Up a Server Cluster for Enterprise Web Apps – Part 3
In this three-part tutorial, we will discover how to set up a server cluster using Alibaba Cloud ECS and WordPress.
4591 0
Setting Up a Server Cluster for Enterprise Web Apps – Part 3
|
2月前
|
JSON 小程序 JavaScript
uni-app开发微信小程序的报错[渲染层错误]排查及解决
uni-app开发微信小程序的报错[渲染层错误]排查及解决
682 7
|
2月前
|
小程序 JavaScript 前端开发
uni-app开发微信小程序:四大解决方案,轻松应对主包与vendor.js过大打包难题
uni-app开发微信小程序:四大解决方案,轻松应对主包与vendor.js过大打包难题
742 1
|
3天前
|
供应链 搜索推荐 API
1688APP原数据API接口的开发、应用与收益(一篇文章全明白)
1688作为全球知名的B2B电商平台,通过开放的原数据API接口,为开发者提供了丰富的数据资源,涵盖商品信息、交易数据、店铺信息、物流信息和用户信息等。本文将深入探讨1688 APP原数据API接口的开发、应用及其带来的商业收益,包括提升流量、优化库存管理、增强用户体验等方面。
25 6
|
4天前
|
机器学习/深度学习 前端开发 算法
婚恋交友系统平台 相亲交友平台系统 婚恋交友系统APP 婚恋系统源码 婚恋交友平台开发流程 婚恋交友系统架构设计 婚恋交友系统前端/后端开发 婚恋交友系统匹配推荐算法优化
婚恋交友系统平台通过线上互动帮助单身男女找到合适伴侣,提供用户注册、个人资料填写、匹配推荐、实时聊天、社区互动等功能。开发流程包括需求分析、技术选型、系统架构设计、功能实现、测试优化和上线运维。匹配推荐算法优化是核心,通过用户行为数据分析和机器学习提高匹配准确性。
23 3
|
10天前
|
移动开发 小程序 PHP
校园圈子论坛系统采取的PHP语音和uni账号开发的小程序APP公众号H5是否只需要4800元?是的,就是只需要4800元
关于校园圈子论坛系统采用PHP语言和uni-app开发的小程序、APP、公众号和H5是否仅需4800元这个问题,实际上很难给出一个确定的答案。这个价格可能受到多种因素的影响
40 8
|
6天前
|
人工智能 小程序 数据处理
uni-app开发AI康复锻炼小程序,帮助肢体受伤患者康复!
近期,多家康复机构咨询AI运动识别插件是否适用于肢力运动受限患者的康复锻炼。本文介绍该插件在康复锻炼中的应用场景,包括康复运动指导、运动记录、恢复程度记录及过程监测。插件集成了人体检测、姿态识别等功能,支持微信小程序平台,使用便捷,安全可靠,帮助康复治疗更加高效精准。
|
27天前
|
人工智能 小程序 搜索推荐
uni app下开发AI运动小程序解决方案
本文介绍了在小程序中实现AI运动识别的解决方案。该方案依托于UNI平台,通过高效便捷的插件形式,实现包括相机抽帧控制、人体识别、姿态识别等在内的多项功能,无需依赖后台服务器,大幅提高识别效率和用户体验。方案内置多种运动模式,支持自定义扩展,适用于AI健身、云上赛事、AI体测等多场景,适合新开发和存量改造项目。
|
1月前
|
设计模式 Swift iOS开发
探索iOS开发:从基础到高级,打造你的第一款App
【10月更文挑战第40天】在这个数字时代,掌握移动应用开发已成为许多技术爱好者的梦想。本文将带你走进iOS开发的世界,从最基础的概念出发,逐步深入到高级功能实现,最终指导你完成自己的第一款App。无论你是编程新手还是有志于扩展技能的开发者,这篇文章都将为你提供一条清晰的学习路径。让我们一起开始这段旅程吧!
|
1月前
|
小程序 数据挖掘 UED
开发1个上门家政小程序APP系统,都有哪些功能?
在快节奏的现代生活中,家政服务已成为许多家庭的必需品。针对传统家政服务存在的问题,如服务质量不稳定、价格不透明等,我们历时两年开发了一套全新的上门家政系统。该系统通过完善信用体系、提供奖励机制、优化复购体验、多渠道推广和多样化盈利模式,解决了私单、复购、推广和盈利四大痛点,全面提升了服务质量和用户体验,旨在成为家政行业的领导者。

热门文章

最新文章

下一篇
DataWorks