Skip to content

Commit 2a6881c

Browse files
docs
1 parent 0318956 commit 2a6881c

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

README.md

+35-32
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
</p>
44

55
<p align="center">
6-
An utility library for collecting web performance metrics<br />
6+
A utility library for collecting web performance metrics<br />
77
that affect user experience.
88
</p>
99

1010
<p align="center">
11-
<a href="#">Why?</a> • <a href="#example">Usage</a> • <a href="#api">API</a> • <a href="#credits">Credits</a>
11+
<a href="#">Why?</a> • <a href="#usage">Usage</a> • <a href="#api">API</a> • <a href="#credits">Credits</a>
1212
</p>
1313

1414
<br/>
@@ -24,12 +24,12 @@ UXM is a modular library that allows to combine various functions and collect th
2424
* Collect RUM data.
2525
* Build private version of [Chrome User Experience Report](https://developers.google.com/web/tools/chrome-user-experience-report/).
2626
* Audit the page performance using Puppeteer ([example](./test/index.js)).
27-
* Dynamically evaluate performance of the user's browser and adapt your app.
27+
* Dynamically evaluate the performance of the user's device and adapt the UI.
2828

2929
**Features**:
3030

3131
* Modular design based on ES modules.
32-
* Small size (1kb gzip). It's usually smaller, if you remove unused functions using [Tree Shaking](https://webpack.js.org/guides/tree-shaking/).
32+
* Small size (1kb gzip). It's usually smaller if you use [Tree Shaking](https://webpack.js.org/guides/tree-shaking/).
3333
* Graceful support of latest browser APIs like [Performance Paint Timing](https://developer.mozilla.org/en-US/docs/Web/API/PerformancePaintTiming), [Network Information](https://wicg.github.io/netinfo/), or [Device Memory](https://w3c.github.io/device-memory/).
3434
* Fully featured [User Timing API](https://developer.mozilla.org/en-US/docs/Web/API/User_Timing_API) support.
3535
* Lightweight device type parser.
@@ -44,12 +44,13 @@ yarn add uxm
4444
npm i -S uxm
4545
```
4646

47-
Import `uxm` and call it in the end of the page loading to collect [CrUX like data](https://developers.google.com/web/tools/chrome-user-experience-report/):
47+
Import `uxm` and call it at the end of the page loading to collect [CrUX-like data](https://developers.google.com/web/tools/chrome-user-experience-report/):
4848

4949
```js
5050
import { uxm } from 'uxm'
5151

5252
uxm().then(metrics => {
53+
console.log(metrics) // ->
5354
{
5455
"deviceType": "desktop",
5556
"effectiveConnectionType": "4g",
@@ -61,7 +62,7 @@ uxm().then(metrics => {
6162
})
6263
```
6364

64-
Collect just 2 performance metrics associated with `url`:
65+
Or collect 2 performance metrics associated with URL:
6566

6667
```js
6768
import { getUrl, getFirstContentfulPaint, getDomContentLoaded } from 'uxm'
@@ -73,7 +74,7 @@ const metrics = {
7374
}
7475
```
7576

76-
Analyze current device and connection:
77+
Or analyze current device and connection:
7778

7879
```js
7980
import { getDeviceType, getDeviceMemory, getEffectiveConnectionType } from 'uxm'
@@ -87,19 +88,21 @@ const device = {
8788

8889
## API
8990

90-
An API is designed in the way that you can combine different functions and collect the data you need.
91+
An API is a set of pure functions with one exception to `uxm`,
92+
which is a meta-function to collect multiple metrics at once.
9193

9294
### uxm(opts = {})
9395

94-
Returns a `Promise` that resolves after `onLoad` event triggered.
96+
Returns a Promise that resolves after `load` event fired.
9597
A default set of metrics is defined by [Chrome User Experience Report](https://developers.google.com/web/tools/chrome-user-experience-report/), but you can customize them using options (`url`, `userAgent`, `deviceMemory`, `userTiming`, `longTasks`, `resources`).
9698

97-
Pass `all` to get the full report:
99+
Or pass `all` to get the full report:
98100

99101
```js
100102
import { uxm } from 'uxm'
101103

102104
uxm({ all: true }).then(metrics => {
105+
console.log(metrics) // ->
103106
{
104107
"deviceType": "phone",
105108
"effectiveConnectionType": "4g",
@@ -142,7 +145,7 @@ uxm({ all: true }).then(metrics => {
142145

143146
### mark(markName)
144147

145-
Create [User Timing](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark) mark to mark important loading event. Convenient shortcut for `window.performance.mark`.
148+
Create [User Timing mark](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark) to mark important loading event. A convenient shortcut for `window.performance.mark`.
146149

147150
```js
148151
import { mark } from 'uxm'
@@ -156,8 +159,8 @@ mark('page fully loaded')
156159

157160
### measure(measureName, [startMarkName])
158161

159-
Create [User Timing](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark) measure to evaluate timing between 2 marks.
160-
Convenient shortcut for `window.performance.measure`.
162+
Create [User Timing measure](https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark) to evaluate timing between 2 marks.
163+
A convenient shortcut for `window.performance.measure`.
161164

162165
```js
163166
import { mark, measure } from 'uxm'
@@ -169,14 +172,14 @@ measure('fonts loaded', 'start load fonts')
169172

170173
### getUserTiming()
171174

172-
Returns an array with collected performance marks/measures. Each item contains:
175+
It returns an array with collected performance marks/measures. Each item contains:
173176

174177
* `type` - "mark" or "measure"
175178
* `name` - unique name
176179
* `startTime` - start time since page load
177180
* `duration` - measure duration
178181

179-
Example response:
182+
Example:
180183

181184
```json
182185
[
@@ -196,54 +199,54 @@ Example response:
196199

197200
### getFirstContentfulPaint()
198201

199-
Returns the time when first paint which includes text, image (including background images), non-white canvas, or SVG happened.
202+
It returns the time when first paint which includes text, image (including background images), non-white canvas, or SVG happened.
200203
[W3C draft for Paint Timing 1](https://w3c.github.io/paint-timing).
201204

202205
### getFirstPaint()
203206

204-
Similar to `getFirstContentfulPaint` but different when First Paint has no content.
207+
It's similar to `getFirstContentfulPaint` but may contain a different value when First Paint is just background change without content.
205208

206209
### getDomContentLoaded()
207210

208-
Returns the time when [`DOMContentLoaded` event](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) was fired.
211+
It returns the time when [`DOMContentLoaded` event](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) was fired.
209212

210213
### getOnLoad()
211214

212-
Returns the time when [`load` event](https://developer.mozilla.org/en-US/docs/Web/Events/load) was fired.
213-
214-
### getDeviceType()
215-
216-
Returns "phone", "tablet", or "desktop" using lightweight, [heavy-tested]('./test/device.js') the User-Agent parser.
215+
It returns the time when [`load` event](https://developer.mozilla.org/en-US/docs/Web/Events/load) was fired.
217216

218217
### getEffectiveConnectionType()
219218

220-
Returns the effective connection type (“slow-2g”, “2g”, “3g”, “4g”) string as determined by round-trip and bandwidth values.
219+
It returns the effective connection type (“slow-2g”, “2g”, “3g”, or “4g”) string as determined by round-trip and bandwidth values.
221220
[W3C draft for Network Information API](http://wicg.github.io/netinfo/).
222221

222+
### getDeviceType()
223+
224+
It returns the device type ("phone", "tablet", or "desktop") string using the lightweight [heavy-tested]('./test/device.js') user-agent parser.
225+
223226
### getDeviceMemory()
224227

225-
Returns "full" or "lite" string, depends if available memory is bigger than 1 GB.
228+
It returns the device memory ("full" or "lite") string, depends if available memory is bigger than 1 GB.
226229
Learn more about [Device Memory](https://developers.google.com/web/updates/2017/12/device-memory).
227230

228231
### getUrl()
229232

230-
Returns a current page URL. Convenient shortcut for `window.location.href`.
233+
It returns a current page URL. A convenient shortcut for `window.location.href`.
231234

232235
### getUserAgent()
233236

234-
Returns a User-Agent string. Convenient shortcut for `window.navigator.userAgent`.
237+
It returns a User-Agent string. A convenient shortcut for `window.navigator.userAgent`.
235238

236239
### getResources()
237240

238-
Returns an array with performance information for each resource on the page. Each item contains:
241+
It returns an array of performance information for each resource on the page. Each item contains:
239242

240243
* `url` - resource URL
241-
* `type` - one of types: "navigation", "link", "img", "script", "xmlhttprequest", "font"
244+
* `type` - one of resource types ("navigation", "link", "img", "script", "xmlhttprequest", or "font")
242245
* `size` - transferred size in bytes
243246
* `startTime` - when load started
244247
* `duration` - loading time in milliseconds
245248

246-
Example response:
249+
Example:
247250

248251
```json
249252
[
@@ -281,8 +284,8 @@ Example response:
281284

282285
### getLongTasks()
283286

284-
Returns an array of `{ startTime, duration }` pairs.
285-
Until `buffered` flag supported, you need to add this script to the `<head />` in order to collect all Long Tasks:
287+
It returns an array of `{ startTime, duration }` pairs.
288+
Until `buffered` flag supported, you need to add extra script to the `<head />` to collect all Long Tasks:
286289

287290
```html
288291
<script>

0 commit comments

Comments
 (0)