当前位置: 首页 > 编程日记 > 正文

小程序前端性能测试_如何提高前端应用程序的性能

小程序前端性能测试

If your website takes longer than 3 seconds to load, you could already be losing nearly half of your visitors.

如果您的网站加载时间超过3秒,则可能已经失去了将近一半的访问者。

Yes this is a fact, proven by several research studies. Long loading times can have a devastating impact on your application’s conversion rates. On the other hand, optimising page load time leads to noticeable improvements in customer experience, conversion rates, SEO and ultimately, your product’s success.

是的,这是事实,已通过多项研究证明。 较长的加载时间可能会对应用程序的转换率产生毁灭性的影响。 另一方面,优化页面加载时间可以显着改善客户体验,转换率,SEO,并最终提高产品的成功率

So let’s say that you have recently built a website or a frontend application using a modern JS framework (Angular, React, VueJS etc.). How can we make sure that performance is not going to hold it back from success?

假设您最近使用现代JS框架(Angular,React,VueJS等)构建了网站或前端应用程序。 我们如何确保绩效不会阻碍成功?

First things first. We have to somehow gather some data. When it comes to measuring a frontend application’s performance, the tools I trust the most are:

首先是第一件事。 我们必须以某种方式收集一些数据 。 在衡量前端应用程序的性能时,我最信任的工具是:

  • Google chrome’s Lighthouse

    谷歌浏览器的灯塔

  • Speedcurve

    速度曲线

Both tools can help you keep track of all the major performance KPIs (Pagespeed Index, Time to Interactive, First Contentful Paint, etc.).

两种工具都可以帮助您跟踪所有主要的性能KPI(Pagespeed Index,交互时间,First Contentful Paint等)。

Lighthouse is included in your Chrome’s dev-tools, and by analysing your website/web-app, it can give you some really useful hints on how to boost it up.

Chrome的开发工具中包含Lighthouse ,通过分析您的网站/网络应用,它可以为您提供一些非常有用的提示,以助您提升它。

With Speedcurve you can have all these KPIs, plus the ability to monitor them across time.

使用Speedcurve,您可以拥有所有这些KPI,并且能够跨时间监控它们。

So now that we are able to measure our success, let’s move on with optimising the parts of our website that play the biggest role.

因此,既然我们已经能够衡量我们的成功,那么让我们继续优化网站中发挥最大作用的部分。

图片 (Images)

Images are a key part of every website. On average, images make up for more than 60% of data that are loaded on web pages. Being such a critical component of almost all websites, image optimisation is, in my opinion, the most important, and perhaps the lowest hanging fruit.

图片是每个网站的关键部分。 平均而言,图像占网页上加载的数据的60%以上。 在几乎所有网站中,图像优化都是至关重要的组成部分,在我看来,图像优化是最重要的,也许是效果最差的结果。

1.调整图像大小并使其响应。 (1. Resize your images and make them responsive.)

The most important thing to check is that you are not using a bigger resolution than the one you really need. So you have to resize your images to fit exactly the requirements of your layout.

要检查的最重要的事情是您使用的分辨率不比实际需要的分辨率高。 因此,您必须调整图像大小以完全适合您的布局要求。

Furthermore, you have to make sure that your images are as responsive as your layout is. There is a great tool that I have been using lately, which can help you generate all the different versions of the images that you might need and also generate the HTML5 code that can utilise them. It’s called Responsive Image Breakpoints Generator. I usually prefer generating 8–10 different images.

此外,您必须确保图像与布局一样敏感 。 我最近一直在使用一个很棒的工具,它可以帮助您生成可能需要的所有不同版本的图像,并生成可以利用它们HTML5代码。 它称为响应图像断点生成器 。 我通常更喜欢生成8–10个不同的图像。

Of course you can use the generated HTML5 code in any frontend app or website. In addition, if you are into gulp, you could automate this process with the gulp-responsive plugin.

当然,您可以在任何前端应用程序或网站中使用生成HTML5代码。 另外,如果您喜欢gulp,则可以使用gulp响应插件自动执行此过程。

2.确保它们是延迟加载的。 (2. Make sure they are lazy loaded.)

Lazy loading basically means that we defer the loading of images that are not required immediately. Typically, any image that is not visible to the users on their current viewport, can be loaded at a later point in time, when the image enters or is about to enter the viewport.

延迟加载基本上意味着我们推迟了不需要立即加载的图像的加载。 通常,当用户进入或即将进入视口时,可以在以后的某个时间点加载用户在其当前视口中不可见的任何图像。

No matter which framework you are using, you can find a plugin that can lazy-load the images for you (e.g. v-lazy-image in VueJS), however you could build your own implementation too. Just make sure that you are utilising the modern way to detect when an element enters or exits the browser’s viewport, the IntersesectionObserver API.

无论使用哪种框架,都可以找到一个可以为您延迟加载图像的插件(例如VueJS中的v-lazy-image ),但是您也可以构建自己的实现。 只要确保您正在利用现代化的方法来检测元素何时进入或退出浏览器的视口,即IntersesectionObserver API 。

奖励:使用CDN进行图像传递 (Bonus: Use a CDN for image delivery)

If you have already optimised the size and the number of images that your website loads, and especially if it’s going to be available globally, you could also use a content delivery network (CDN) to serve them.

如果您已经优化了网站加载的图像的大小和数量,尤其是要使其在全球范围内可用,则还可以使用内容分发网络 (CDN)为它们提供服务。

In a few words, a CDN caches your images on its globally distributed network of servers. So if a user from Australia requests an image from your website, instead of retrieving that image from your server in Europe, the CDN is going to deliver it from another one, closer to that user in Australia. This cuts down the round trip time needed to load the image.

简而言之,CDN将您的映像缓存在其全球分布的服务器网络上。 因此,如果来自澳大利亚的用户从您的网站上请求图像,而不是从欧洲的服务器中检索该图像,则CDN将从另一个更接近澳大利亚用户的位置传递该图像。 这样可以减少加载图像所需的往返时间。

CSS,JS和HTML (CSS, JS and HTML)

All modern frameworks optimise your code during the production build time (code-splitting, tree-shaking, minification, etc.). What you can do on top of that?

所有现代框架在生产构建期间都会优化您的代码(代码拆分,摇树,缩小等)。 您还可以做什么?

1.优化主HTML文档 (1. Optimise the main HTML document)

HTML is the backbone of nearly every web app. When it comes to referencing resources within your HTML document there are a few best practices you should follow. It is recommended to:

HTML是几乎每个Web应用程序的骨干。 在HTML文档中引用资源时,应遵循一些最佳实践。 建议:

  • Place CSS references at the top of your HTML document’s header in order to ensure progressive rendering.

    将CSS引用放在HTML文档标题的顶部,以确保逐步呈现。
  • Place JavaScript attributes at the bottom of your HTML body and prefer async script loading. This will prevent any <script> tags from blocking the HTML rendering process.

    将JavaScript属性放在HTML正文的底部,并喜欢异步脚本加载 。 这将防止任何<scri pt>标签阻止HTML呈现过程。

2.确保只加载所需的内容 (2. Make sure you only load what you need)

Angular, React, and VueJS all provide you with lazy-loading features. You only have to split your code properly, according to your own needs and load only the modules that you need, as soon as you really need them. For instance, if you have an e-commerce app, you have to make sure that the Basket module or the Payments module are not loaded when the user is in the home page.

Angular,React和VueJS都为您提供了延迟加载功能。 您只需要根据自己的需要适当地拆分代码,并在真正需要它们时立即加载所需的模块。 例如,如果您有一个电子商务应用程序,则必须确保在用户进入主页时未加载购物篮模块或“付款”模块。

压缩与缓存 (Compression & Caching)

In general, for all the assets that are essential to your frontend (images & code) you should apply compression and cache them properly.

通常,对于前端必不可少的所有资产(图像和代码),您应该应用压缩并适当地缓存它们。

File compression will make your app’s assets a bit lighter and decrease the round trip time needed to serve them. One of the most commonly used file compression methods is Gzip, an excellent method for shrinking code chunks, documents, images and audio files.

文件压缩将使您的应用程序资产更轻,并减少提供这些资源所需的往返时间。 最常见的之一 使用的文件压缩方法是Gzip ,这是一种用于缩小代码块,文档,图像和音频文件的出色方法。

Brotli is another file compression algorithm, and it’s growing in popularity. This open source algorithm is regularly updated by software engineers from Google and other organisations. It has proven itself to compress files at a much better ratio than other existing methods.

Brotli是另一种文件压缩算法,并且越来越流行。 这种开源算法由Google和其他组织的软件工程师定期更新。 它已经证明自己可以以比其他现有方法更好的比率压缩文件。

You can enable your preferred compression method on nginx, apache or whichever server you are using, by modifying their configuration files (enabling brotli on nginx or enabling brotli on apache).

您可以通过修改配置文件( 在nginx上 启用brotli或在apache 上 启用brotli )在nginx,apache或正在使用的任何服务器上启用首选压缩方法。

When it comes to caching, the most commonly used caching technique (also recommended by Lighthouse) is called Leverage Browser Caching. Again, you can enable it by modifying your server’s configuration files (enabling Leverage Browser Caching).

当涉及到缓存时,最常用的缓存技术(也被Lighthouse建议)被称为Leverage Browser Caching 。 同样,您可以通过修改服务器的配置文件( 启用“利用浏览器缓存” )来启用它。

摘要 (Summary)

When it comes to websites and frontend applications, performance is a huge topic and we should take it seriously.

对于网站和前端应用程序,性能是一个巨大的话题,我们应该认真对待。

I hope this article helped you understand and enabled you to tackle some of the most important things that we need to take care of when we want to improve an application’s performance.

我希望本文能帮助您理解并帮助您解决一些我们想提高应用程序性能时需要注意的最重要的事情。

For a detailed checklist, make sure that you check out the Front-End-Performance-Checklist.

有关详细的清单,请确保签出了“ 前端性能清单” 。

Cheers! ?

干杯! ?

翻译自: https://www.freecodecamp.org/news/how-to-boost-your-front-end-applications-performance-72ce872b08c/

小程序前端性能测试

相关文章:

10-TypeScript中的接口

接口是一种规约的约定&#xff0c;从接口继承的类必须实现接口的约定。在高级开发中&#xff0c;通常接口是用于实现各种设计模式的基础&#xff0c;没有接口&#xff0c;设计模式无从谈起。 定义接口&#xff1a; interface ILog{recordlog():boolean; } 类从接口继承&#xf…

样式集(六)仿微信通讯录样式

效果图&#xff1a; 这里有引用到 自定义底部导航&#xff0c;自定义底部导航组件链接 <!--pages/chatList/chatList.wxml--><!-- <include src"/components/common/common" /> --> <view class"top"><view class"pageTi…

WCF动态添加ServiceKnownType

WCF中传输自定义类型时&#xff0c;必须在服务接口类&#xff08;服务协定&#xff09;上加上ServiceKnownType(typeof(yourClass)), 在实际应用中比较麻烦&#xff0c;可以用动态的办法来实现动态添加。 服务接口类&#xff0c;加上一行 [ServiceKnownType("GetKnownType…

博客 rss 如何使用_如何使用RSS从您的GatsbyJS博客自动交叉发布

博客 rss 如何使用With the recent exodus from Medium many developers are now creating their own GatsbyJS Blogs and then cross-posting to Medium or publications like freecodecamp.org and dev.to.随着Medium最近的离职&#xff0c;许多开发人员现在正在创建自己的Ga…

大型技术网站的技术( 高并发、大数据、高可用、分布式....)(一)

面对高并发、大流量、高可用、海量数据、用户分布广泛、网络情况复杂这类网站系统我们如何应对&#xff1f;&#xff1f;&#xff1f; 第一阶段 一台服务器不行就上多台服务器 1.应用程序与数据服务分离 将应用程序、数据库、文件等资源放在一台服务器上&#xff0c;面对海量…

BestCoder Round #65 B C D || HDU 5591 5592 5593

B 题意&#xff1a;ZYB在远足中,和同学们玩了一个“数字炸弹”游戏&#xff1a;由主持人心里想一个在[1,N][1,N]中的数字XX&#xff0c;然后玩家们轮流猜一个数字&#xff0c;如果一个玩家恰好猜中XX则算负&#xff0c;否则主持人将告诉全场的人当前的数和XX比是偏大还是偏小&a…

数组去重,ES6数组去重 new Set()

普通数组去重 var b [...new Set([1,2, 3, 4, 5, 5, 5, 5])]console.log(b); 输出结果&#xff1a; 包含对象的数组去重 var o {a:1}var b [...new Set([o, o, 3, 4, 5, 5, 5, 5])]console.log(b); 输出结果&#xff1a; 包含对象的数组去重有一个坑 var b [...new Set([{…

使用angular的好处_在项目中使用Angular的最大好处

使用angular的好处by Irina Sidorenko伊琳娜西多连科(Irina Sidorenko) 在项目中使用Angular的最大好处 (The top benefits of using Angular for your project) 在项目实施中使用Angular的11个理由及其好处 (11 reasons to use Angular and its benefits for your project im…

python之路——模块和包

一、模块 1、什么是模块&#xff1f; 常见的场景&#xff1a;一个模块就是一个包含了Python定义和声明的文件&#xff0c;文件名就是模块名字加上.py的后缀。 但其实import加载的模块分为四个通用类别&#xff1a; 1、使用Python编写的代码&#xff08;.py文件&#xff09; 2、…

夺命雷公狗---linux NO:3 centos_mini版的安装和备份

废话不多说&#xff0c;和前面的其实是差不多的&#xff0c;如下图所示&#xff1a; 安装其实是和桌面版的差不多的&#xff0c;但是经典版的不能自定义分区&#xff08;如详细区&#xff0c;如home之类的&#xff09;。。。 因为我们使用的是命令行方式的所以直接选英文&#…

快速学习 async await 的使用, Demo 解析

async 和 await 字面都很好理解&#xff0c;分别是异步和等待。 来两个简单的 demo&#xff0c; demo1 tt2(){return new Promise(rps>{setTimeout(() > {rps(true)}, 1500);})},async tt1(){var a await this.tt2();console.log(a)},/*** 生命周期函数--监听页面加载*…

小型工作室创业项目_为什么新开发人员应该在小型创业公司工作

小型工作室创业项目In my first year of working in the industry (6 months as an intern, 6 months as a full-time employee), I worked at startups that were less than 10 people large. I was one of the only 2 or 3 developers, and usually one of the first. Throug…

head first python菜鸟学习笔记(第六章)

1. Python提供字典&#xff0c;允许有效组织数据&#xff0c;将数据与名关联&#xff0c;从而实现快速查找&#xff0c;而不是以数字关联。 字典是内置数据结构&#xff0c;允许将数据与键而不是数字关联。这样可以使内存中的数据与实际数据的结构保持一致。&#xff1f;&#…

小程序聊天室开发,发送文字,表情,图片,音频,视频,即时通讯,快速部署,可定制开发

效果图&#xff1a; 微信小程序聊天功能模块&#xff0c;现在已经支持发送图片&#xff0c;文字&#xff0c;音频&#xff0c;视频&#xff0c;表情&#xff0c;在线即时聊天啦。 需要做的可以联系我微信。13977284413 上代码&#xff1a; <view class"bo">…

常用浏览器插件

modify headers &#xff1a;firefox的IP伪造插件 httpRequester&#xff1a;firefox的模拟http请求插件JSON-handle&#xff1a;chrome格式化json插件firebug&#xff1a;firefox查看http请求工具firepath&#xff1a;firefox中获取元素路径转载于:https://www.cnblogs.com/xx…

编码中统一更该变量的快捷键_更多项目想法,以提高您的编码技能

编码中统一更该变量的快捷键Two weeks ago I published an article containing 15 project ideas that you can build to level up your coding skills, and people were very excited about that resource.两周前&#xff0c;我发表了一篇文章&#xff0c;其中包含15个项目构想…

My97DatePicker日历控件日报、每周和每月的选择

My97DatePicker日历控件日报、每周和每月的选择 1、设计源代码 <% page language"java" import"java.util.*" pageEncoding"UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><h…

DotNet Core Console 程序使用NLog

参考&#xff1a;https://github.com/NLog/NLog/wiki/Tutorial 步骤&#xff1a; 1. 使用Nuget安装NLog.Extensions.Logging Install-Package NLog.Extensions.Logging 2.编写代码&#xff08;到这步运行代码&#xff0c;不报错&#xff0c;但是也不会有log输出&#xff0c;因为…

小程序判断用户在线状态

在页面的两个生命周期组件里面 onShow() {console.log(-----上线线)let info wx.getStorageSync(chat_item)DB.collection(friends).where({_id: info._id}).get().then(res > {console.log(-----, res)if (res.data[0].a wx.getStorageSync(userInfo)._openid) {console.…

react.js做小程序_如何使用React.js构建现代的聊天应用程序

react.js做小程序In this tutorial, I will guide you to build your own group chat application using React, React Router, and CometChat Pro. Yes, rather than roll out our own server, we will instead use CometChat Pro to handle the real-time sending and receiv…

RAP Mock.js语法规范

Mock.js 的语法规范包括两部分&#xff1a; 数据模板定义规范&#xff08;Data Template Definition&#xff0c;DTD&#xff09;数据占位符定义规范&#xff08;Data Placeholder Definition&#xff0c;DPD&#xff09;1.数据模板定义规范 DTD 数据模板中的每个属性由 3 部分…

NSDictionary、NSMutableDictionary基本使用

郝萌主倾心贡献&#xff0c;尊重作者的劳动成果。请勿转载。假设文章对您有所帮助&#xff0c;欢迎给作者捐赠&#xff0c;支持郝萌主&#xff0c;捐赠数额任意&#xff0c;重在心意^_^ 我要捐赠: 点击捐赠Cocos2d-X源代码下载&#xff1a;点我传送游戏官方下载&#xff1a;htt…

h5轮播图及效果图

效果图&#xff1a; 代码&#xff1a; <!doctype html> <html><head><meta charset"utf-8"><title>jQuery响应式卡片轮播切换代码</title><link rel"stylesheet" type"text/css" href"css/style.c…

性能测试回归测试_自动网站性能回归测试

性能测试回归测试by Adam Henson亚当汉森(Adam Henson) 如何使用Foo自动执行网站性能回归测试 (How to automate website performance regression testing with Foo) 使用部署后步骤自动执行连续交付工作流程中的性能回归测试 (Using a post deploy step to automate performa…

【html】【13】特效篇--下拉导航

html代码&#xff1a; 1 <!DOCTYPE html>2 <html>3 <head>4 <meta http-equiv"Content-Type" content"text/html; charsetUTF-8">5 <title>Bootstrap导航条鼠标悬停下拉菜单</title>6 <li…

小程序获取用户所在城市完整代码

小程序目录结构 插入提示: 1. 申请开发者密钥&#xff08;key&#xff09;&#xff1a; 申请密钥 2. 下载微信小程序JavaScriptSDK&#xff0c;下载地址 下载完成后放入utils文件夹下引用即可 3. 安全域名设置&#xff0c;在“设置” -> “开发设置”中设置req…

prolog_如何通过观看权力的游戏学习Prolog

prologby Rachel Wiles瑞秋威尔斯(Rachel Wiles) 如何通过观看权力的游戏学习Prolog (How to learn Prolog by watching Game of Thrones) 他们死了吗&#xff1f; 他们还活着吗&#xff1f; 她是他的姨妈吗&#xff1f; 不用把精力浪费在2011年&#xff0c;而可以使用Prolog节…

身份证号码对应地区-官方措辞:行政区划代码

身份证前6位代表着该身份证的籍贯在哪里&#xff0c;而官方的措辞则为&#xff1a;行政区划代码 如何找到最新的行政区划代码了&#xff1f; 通过&#xff1a;http://blog.sina.com.cn/s/blog_5a76dae20100tqv5.html 此人的博客得知&#xff0c;行政区划代码是国家统计局统计的…

Jquery_操作cookies

首先引入jquery.cookie.js jquery.cookie.js下地址&#xff1a;http://plugins.jquery.com/cookie/ 操作文档&#xff1a; https://github.com/carhartl/jquery-cookie#readme 创建cookies&#xff1a; $.cookie(name, value); 设置有效期&#xff1a; 设置七天过期 $.cookie(n…

rem转rpx工具

对样式进行格式化&#xff0c;然后根据 “rem” 进行拆分&#xff0c;这样就会拆分成一个数组 [str1,str2,str3...,str6], 除了最后一个元素&#xff0c;前边的元素都会以 “rem” 样式的数值结尾&#xff0c; 然后在对数组中的元素字符串进行再次根据 “&#xff1a;” 进行…