硬件断点反跳似乎_高性能应用程序:多路复用,反跳,系统字体和其他技巧
硬件断点反跳似乎
by Atila Fassina
通过阿蒂拉·法西纳(Atila Fassina)
高性能应用程序:多路复用,反跳,系统字体和其他技巧 (High Performance Apps: Multiplexing, Debouncing, System Fonts, and other tricks)
Here are some performance tips for your client-side application that you can start using immediately.
这里是您的客户端应用程序的一些性能提示,您可以立即开始使用。
These will boost your app’s perceived performance significantly. And most of them only require quick tweaks to your app.
这些将大大提高您应用的感知性能 。 而且大多数只需要快速调整您的应用程序即可。
预加载您的资源 (Preload your resources)
rel="preload"
is a way of letting your browser know that a specific resource is important. This way, your browser will fetch the resource as quickly as possible. Then it will store it locally until it finds the expected reference in the DOM.
rel="preload"
是一种让浏览器知道特定资源很重要的方法。 这样,您的浏览器将尽快获取资源。 然后它将在本地存储它,直到在DOM中找到期望的引用为止。
Here are some examples of using a link
with this attribute:
以下是使用带有此属性的link
一些示例:
The as
attribute is mandatory here, because it tells the browser what filetype that it is fetching. This way it can interpret the request and add the proper headers. Otherwise, your request would have the incorrect mime/type
so your browser wouldn’t be able to parse it.
as
属性在这里是必需的,因为它告诉浏览器要获取的文件类型。 这样,它可以解释请求并添加适当的标头。 否则,您的请求将具有错误的mime/type
因此您的浏览器将无法解析它。
By the way, mime/type
is the file type declaration that developers use on the web. This is similar to the file extensions on your desktop operating system. If you have the incorrect mime/type
, the browser won’t know how to parse the file.
顺便说一句, mime/type
是开发人员在网络上使用的文件类型声明。 这类似于桌面操作系统上的文件扩展名。 如果您的mime/type
不正确,浏览器将不会解析该文件。
Font files are a bit trickier to preload. Here are some things to keep in mind:
字体文件要预加载有点棘手。 这里要记住一些事情:
crossorigin
—The W3C requires that font fetches be anonymous. In a nutshell, this means even when the request is coming from the same domain, it will be treated as a cross-origin request.crossorigin
— W3C要求字体提取是匿名的。 简而言之,这意味着即使请求来自同一域,也将其视为跨源请求。type
— This specifies which format the browser should use when fetching the font.type
—type
—指定浏览器在获取字体时应使用的格式。
Also, be sure to only add the first format to your font-face
declaration. Preloading multiple font formats is against best practices, is bad UX, and wastes your users’ bandwidth.
另外,请确保仅将第一种格式添加到您的font-face
声明中。 预加载多种字体格式违反了最佳实践,是糟糕的UX,并且浪费了用户的带宽。
You can read more about preloading here.
您可以在此处阅读有关预加载的更多信息 。
使用特定于操作系统的字体 (Use Operating System-specific fonts)
By using system fonts, it’s possible to emulate your users’ Operational System’s look and feel. This way, your application has a better chance of looking like a native one, while saving your user the trouble of downloading more resources.
通过使用系统字体,可以模拟用户操作系统的外观。 这样,您的应用程序更有可能看起来像本机应用程序,同时为用户节省了下载更多资源的麻烦。
Let's analyze more closely each of these declarations:
让我们更仔细地分析以下每个声明:
apple-system: as the name suggests, these target OSX/iOS-related systems
苹果系统 :顾名思义,这些目标与OSX / iOS相关的系统
system-ui: these target the system font, regardless of the system
system-ui :这些目标系统字体,与系统无关
BlinkMacSystemFont: Chrome’s font on MacOS
BlinkMacSystemFont :MacOS上的Chrome字体
Segoe UI: Windows/Windows Phone
Segoe UI :Windows / Windows Phone
Roboto: Android
Roboto :Android
This solution is widely used even though many developers don’t yet know about it. For example, at time of writing this article, it's used at:
即使许多开发人员对此尚不了解,该解决方案仍被广泛使用。 例如,在撰写本文时,它用于:
- GitHub的GitHub
- WordpressWordPress的
- Bootstrap引导程序
- Medium中
- Ghost鬼
- Zeit时代精神
And probably others that I haven't yet heard about.
可能还有其他我还没有听说过的东西。
消除和限制对服务器的呼叫 (Debounce and throttle calls to your server)
Some events get fired many times more than we intend to trigger them. For example: resize, scroll, keypress/keydown/keyup, or change.
有些事件比我们打算触发它们的次数要多得多。 例如:调整大小,滚动,按键/向下键/向上键或更改。
Resize and scroll, for instance, get fired on every pixel. That’s an awful lot of chatter if you just want to adjust some elements on breakpoint, or add a class to a header as the user scrolls down the page.
例如,调整大小和滚动会在每个像素上触发。 如果您只想调整断点上的某些元素,或者在用户向下滚动页面时将一个类添加到标头中,那将是非常麻烦的事情。
If you get an autocomplete, for example, you don’t want to fire on every key press. In most cases, it would be good to start autocompleting after the 3rd character. Especially if you plan to fetch information for that.
例如,如果您获得自动完成功能,则不想在每次按键时都触发。 在大多数情况下,最好在第三个字符之后开始自动填充。 特别是如果您打算为此获取信息。
Debounce holds up your trigger until the event stops firing for a given amount of time (usually 500 milliseconds).
防抖动可保持触发状态,直到事件在给定的时间(通常为500毫秒)内停止触发为止。
Throttle holds up your trigger if it attempts to fire more often than a given interval (usually 25o milliseconds).
如果节气门尝试触发的次数超过给定间隔(通常为25o毫秒),则它会阻止触发器。
使用异步/延迟 (Use async/defer)
Remember the good old window.onload
function? Or moving all the scripts to the bottom of your HTML? Yeah, well, async
and defer
are here to give you some better options.
还记得旧的window.onload
函数吗? 还是将所有脚本移到HTML的底部? 是的, async
和defer
功能可以为您提供更好的选择。
Async will download your script during the HTML parsing. It will run it asynchronously (if possible) — regardless of where it’s declared.
Async会在HTML解析期间下载您的脚本。 它将异步运行(如果可能的话)—无论在何处声明它。
Defer will also download your script during the HTML parsing, though it will only attempt to run your script after the parser is finished. Also, declaring multiple deferred scripts guarantees that they will be executed in declaration order.
Defer还将在HTML解析期间下载您的脚本,尽管它只会在解析器完成后尝试运行您的脚本。 此外,声明多个延迟脚本可确保它们将按声明顺序执行。
<script async src="./my-async-script.js"></script><script defer src="./my-deferred-script.js"></script>
数据:uri和<svg> (data:uri and <svg>)
When adding icons or small image files, an interesting technique is to use data-uri
. A data
URL is usually encoded as base64
and provides an easy way of embedding files into your DOM directly. In a similar way, you can add <s
vg> as markup. This way your SVG image will be parsed and rendered by the browser.
添加图标或小图像文件时,一种有趣的技术是使用data-uri
。 data
URL通常被编码为base64
并提供了一种将文件直接嵌入DOM的简便方法。 以类似的方式,您可以添加<s
vg>作为标记。 这样,您的SVG图像将被浏览器解析和呈现。
Note that using the <s
vg> instead of embedding as an
<img> or icon-font brings other functionalities that are beyond the scope of this article.
请注意,使用<s
vg>而不是as an
<img>或图标字体进行嵌入会带来其他功能,这些功能不在本文的讨论范围之内。
Adding the files straight into your markup instead of referencing them saves you one HTTP request each time. This is nice when your file is so small that it isn’t worth the trouble of making a roundtrip to the server. Especially while on mobile networks, since handshakes can be quite expensive.
直接将文件添加到标记中而不是引用它们,每次都可以节省一个HTTP请求。 当您的文件太小以至于不值得往返服务器时,就很好了。 特别是在移动网络上,因为握手可能会非常昂贵。
使用多路传输 (Use Multiplexing)
If your server is already working with HTTP2, embedding files might not be worthwhile. This happens because HTTP2 has a feature called Multiplexing.
如果您的服务器已经在使用HTTP2,则嵌入文件可能不值得。 发生这种情况是因为HTTP2具有称为多路传输的功能。
This means your browser can send multiple requests and receive multiple responses "bundled" into a single TCP connection. So the workload associated with DNS lookups and handshakes is saved for files coming from the same server.
这意味着您的浏览器可以发送多个请求并接收“ 捆绑 ”到单个TCP连接中的多个响应。 因此,与DNS查找和握手相关的工作负载将保存到来自同一服务器的文件中。
In addition, HTTP2 also provides you with Server Push. This means it’s possible to send files even before the user requests them. This increases the perceived performance significantly.
此外,HTTP2还为您提供服务器推送。 这意味着甚至可以在用户请求文件之前发送文件。 这显着提高了感知性能。
I hope these tips help you improve the perceived performance of your app. If you found this article helpful, give me some claps ?. You can also give me feedback on this on Twitter.
希望这些技巧能帮助您改善应用的感知性能。 如果您觉得这篇文章有帮助,请给我一些鼓掌? 您也可以就T witter给我反馈。
进一步阅读 (Further Reading)
在rel = preload上: (On rel=preload:)
SmashingMagazine — Preload What is it Good for
SmashingMagazine —预加载有什么好处
Zach Letherman — Preload
扎克·莱瑟曼(Zach Letherman)—预紧力
在系统字体上: (On system fonts:)
Bitsofcode — The New System Font Stack?
Bitsofcode —新系统字体堆栈?
Normalize.css — issue#665
Normalize.css —问题#665
翻译自: https://www.freecodecamp.org/news/high-performance-apps-multiplexing-debouncing-system-fonts-and-other-tricks-37c6fd3d7b2d/
硬件断点反跳似乎
相关文章:

jquery仿邮箱文本输入框自动加载邮箱后缀
jquery仿邮箱文本输入框自动加载邮箱后缀 在像百度这样的网站注册时,你会看到输入邮箱会出现自动给用户输入补全主流邮箱。这种对于增加用户体验的小例子已司空见惯。正好看到人家写的这种js功能。还挺不错,使用起来很方便,几乎不用写神呢代码。"傻…

Maven最佳实践:划分模块
所有用Maven管理的真实的项目都应该是分模块的,每个模块都对应着一个pom.xml。它们之间通过继承和聚合(也称作多模块,multi-module)相互关联。那么,为什么要这么做呢?我们明明在开发一个项目,划…

facebook 直播_什么时候是在Facebook Live上直播的最佳时间? 我分析了5,000个Facebook帖子以找出答案。...
facebook 直播by Ofir Chakon由Ofir Chakon 什么时候是在Facebook Live上直播的最佳时间? 我分析了5,000个Facebook帖子以找出答案。 (When is the best time to stream on Facebook Live? I analyzed 5,000 Facebook posts to find out.) Streaming on Facebook …

解决keepalived脑裂问题
检测思路:正常情况下keepalived的VIP地址是在主节点上的,如果在从节点发现了VIP,就设置报警信息 脚本如下: #!/bin/bash # 检查脑裂的脚本,在备节点上进行部署 LB01_VIP10.10.10.229 LB01_IP10.10.10.129 LB02_IP10.10…

iOS 根据中文字符串排序出字母索引
// 传入字符串数组 返回索引字典 - (NSDictionary *)createCharacter:(NSMutableArray *)strArr {NSMutableDictionary *dict [NSMutableDictionary dictionary];for (NSString *stringdict in strArr) {NSString *string stringdict;if ([string length]) {NSMutableString …

devops开发运维训练营_嗨,网络开发人员训练营的毕业生:这是您第一份工作需要了解的内容。...
devops开发运维训练营by Rachel Bird雷切尔伯德(Rachel Bird) 嗨,网络开发人员训练营的毕业生:这是您第一份工作需要了解的内容。 (Hey web dev bootcamp grads: Here’s what you need to know for your first job.) You worked your butt off and gai…

[bzoj1042][HAOI2008]硬币购物
有三种硬币,每种有自己的币值。 然后有n次询问,每次都给出每种硬币的数量和要付的钱s,求有多少种付法。n<1000 s<100000 ------ 不考虑限制,就是个简单dp.... 有限制的时候,我们可以考虑反过来用总的方案数量剪掉…

Windows netstat 查看端口、进程占用
目标:在Windows环境下,用netstat命令查看某个端口号是否占用,为哪个进程所占用. 操作:操作分为两步:(1)查看该端口被那个PID所占用;方法一:有针对性的查看端口,使用命令 …

iOS Named colors do not work prior to iOS 11.0问题解决
原文链接 https://stackoverflow.com/questions/48014246/named-colors-do-not-work-prior-to-ios-11-0-error-referring-to-a-storyboard/52967313#52967313 1 打开对应文件source code 2 粘贴查找 使用正则表达式 color key(.*) name.* 3 用以下代码覆盖 color key$1 …

如何在StackOverflow上获得第一个标签徽章-以及为什么它很重要。
by Angelos Chalaris通过安吉洛斯查拉利斯(Angelos Chalaris) 如何在StackOverflow上获得第一个标签徽章-以及为什么它很重要。 (How to get your first tag badge on StackOverflow — and why it’s important.) Every developer uses StackOverflow in different ways. Som…

int数据类型
1 a 18862 # 取商和余数3 print(a.__divmod__(10)) 4 5 # r反转,想当于 10-18866 print(a.__rsub__(10)) 7 8 # 取绝对值9 print(a.__abs__(), abs(a)) 10 11 #商取整 12 print(a.__floordiv__(10), a // 10) 转载于:https://www.cnblogs.com/xh4528/p/6497629.html

使用Google 官方的控件SwipeRefreshLayout实现下拉刷新功能
之前做东西的时候,经常会用到下拉刷新的功能,之前大家都在使用Github上的一个很著名的开源项目 PullToRefresh 但是,现在好消息来了,google在19.1版本的support-v4兼容包下面正式提供了官方的下拉刷新组件——SwipeRefreshLayout…

iOS 没到年底NSDate 时间出错问题
NSDate *currentDate [NSDate date];//获取当前时间,日期 NSDateFormatter *dateFormatter [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:"yyyy-MM-dd HH:mm:ss"]; // [dateFormatter setDateFormat:"YYYY-MM…

react 统一字段验证_如何使用React的受控输入进行即时表单字段验证
react 统一字段验证by Gosha Arinich通过Gosha Arinich 如何使用React的受控输入进行即时表单字段验证 (How to use React’s controlled inputs for instant form field validation) Controlled inputs enable simple things, like disabling the Submit button when some fi…

UISearchBar和 UISearchDisplayController的使用
感觉好多文章不是很全面,所以本文收集整合了网上的几篇文章,感觉有互相补充的效果。 如果想下载源码来看:http://code4app.com/search/searchbar 。本源码与本文无关 1、searchBar 本例子实现布局:上面是一个navigationController…

iOS 获取指定时间的前后N个月
https://www.cnblogs.com/SUPER-F/p/7298548.html 正数为后 负数为前 -(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(NSInteger)month { NSDateComponents *comps [[NSDateComponents alloc] init]; [comps setMonth:month]; NSCalendar *calender …

JS高级程序设计第五章读书笔记
1.引用类型的值(对象)是引用类型的一个实例。在ES中,引用类型是一种数据结构,用于将数据和功能组织在一起。它们也长被称为类,但这并不妥当。因为ES在技术层面上是一门面对对象的语言,但它并不具备传统的面…

使用Tape和Vue Test Utils编写快速的Vue单元测试
by Edd Yerburgh埃德耶堡(Edd Yerburgh) 使用Tape和Vue Test Utils编写快速的Vue单元测试 (Write blazing fast Vue unit tests with Tape and Vue Test Utils) Tape is the fastest framework for unit testing Vue components.磁带是用于Vue组件进行单元测试的最快框架。 I…

js去除数组中重复值
//第三种方法加强版 Array.prototype.distinctfunction(){ var sameObjfunction(a,b){ var tag true; if(!a||!b)return false; for(var x in a){ if(!b[x]) return false; if(typeof(a[x])object){ tagsameObj(a[x],b[x]); }else{ if(a[x]!b[x]) return false; } } return ta…

CXFServlet类的作用
CXFServlet是Apache CXF框架中的一个核心组件,用于处理HTTP请求并将它们转换为Web服务调用。通过配置CXFServlet,你可以轻松地部署和管理SOAP和RESTful Web服务。

了解jvm对编程的帮助_这是您对社会责任编程的了解
了解jvm对编程的帮助by ?? Anton de Regt由?? 安东德雷格 这是您对社会责任编程的了解 (This is what you need to know about Socially Responsible Programming) 您的才华比银行帐户中的零值多 (Your talent is worth more than lots of zeroes in your bank account) L…

解压和生成 system.imgdata.img ( ext4格式)
另一篇文章讲述了如何解压和生成system.img, 那是针对yaffs2格式的文件系统镜像。 目前越来越多的Android手机放弃了nand, 更多采用了emmc为内部存储设备。 以emmc为存储设备的android手机,其文件系统(/system,/data两个分区)一般采用ext4格式…

简单分析beyond作曲
本人绝对是业余的哈 业余到什么水平呢?正在练习爬格子,还是一个星期练几次那种 先说下《海阔天空》 6,5,4,3 1,2,3,4 简单是简单得不得了,声从低到高,然后再从…

1 OC 对象的本质(一个NSObject 对象占用的内存大小)
1 前言 目录 1 前言 2 一个NSObject占用多少内存 3 为什么呢 ? 4 如何在内存中看呢? OC 的面向对象都是基于C/C 的数据结构实现的 结构体 2 clang 命令转换成c 代码 clang -rewrite-objc main.m -o main.cpp 以上的命令是不分平台进行编译的&…

Xiki:一个开发人员寻求增强命令行界面的能力
by Craig Muth通过克雷格穆斯(Craig Muth) Xiki:一个开发人员寻求增强命令行界面的能力 (Xiki: one developer’s quest to turbocharge the command line interface) I was sitting with my friend Charles in a trendy cafe next to Golden Gate Park in San Fra…

2 OC 对象的本质(一个Student 占用的内存大小)
一 Student 占用的内存空间 补充: 1 成员变量占用字节的大小: 2 内存对齐的规则:结构体的内存大小必须是最大成员变量的内存的倍数。 一个 Student 类,继承自NSObject,有两个属性,首先要知道,int 类型占用…

jdk动态代理源码学习
最近用到了java的动态代理,虽然会用,但不了解他具体是怎么实现,抽空看看了看他的源码。 说到Java的动态代理就不能不说到代理模式,动态代理也就是多了一个’动态’两字,在《大话设计模式》中不是有这句话吗?“反射&…

20162313苑洪铭 第一周作业
20162313苑洪铭 20016-2017-2 《程序设计与数据结构》第1周学习总结 教材学习内容总结 本周观看教材绪论 主要在教我建立一个简单的java程序 内容是林肯的名言 虽然看起来很简单 但是实际上问题重重 总而言之 这一周全是在出现故障的 教材学习中的问题和解决过程 教材学习好像并…

测试驱动开发 测试前移_测试驱动的开发可能看起来是工作的两倍-但无论如何您都应该这样做...
测试驱动开发 测试前移by Navdeep Singh通过Navdeep Singh 测试驱动的开发可能看起来是工作的两倍-但无论如何您都应该这样做 (Test-driven development might seem like twice the work — but you should do it anyway) Isn’t Test Driven Development (TDD) twice the wor…