All Projects → InstantDomain → instant-vitals

InstantDomain / instant-vitals

Licence: MIT license
Simple tools to track and improve your Web Vitals scores

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to instant-vitals

Perfume.js
Web performance library for measuring all User-centric performance metrics
Stars: ✭ 2,533 (+2359.22%)
Mutual labels:  lcp, cls, fid
nestjs-cls
A continuation-local storage (async context) module compatible with NestJS's dependency injection.
Stars: ✭ 110 (+6.8%)
Mutual labels:  cls
pytorch-gan-metrics
Pytorch implementation of common GAN metrics
Stars: ✭ 87 (-15.53%)
Mutual labels:  fid
performance-checklist
📈 A comprehensive list of performance optimization techniques to improve your site's performance
Stars: ✭ 26 (-74.76%)
Mutual labels:  web-vitals
readium-lcp-server
Repository for the Readium LCP Server
Stars: ✭ 47 (-54.37%)
Mutual labels:  lcp
libsais
libsais is a library for linear time suffix array, longest common prefix array and burrows wheeler transform construction based on induced sorting algorithm.
Stars: ✭ 81 (-21.36%)
Mutual labels:  lcp
scroll-padlock
🔒 CSS variables-based scrollbars locker, compatible with all reactive frameworks
Stars: ✭ 12 (-88.35%)
Mutual labels:  cls
metrics
IS, FID score Pytorch and TF implementation, TF implementation is a wrapper of the official ones.
Stars: ✭ 91 (-11.65%)
Mutual labels:  fid
react-hydration-on-demand
Hydrate your React components only when you need to
Stars: ✭ 94 (-8.74%)
Mutual labels:  fid
nuxt-prune-html
🔌⚡ Nuxt module to prune html before sending it to the browser (it removes elements matching CSS selector(s)), useful for boosting performance showing a different HTML for bots/audits by removing all the scripts with dynamic rendering
Stars: ✭ 69 (-33.01%)
Mutual labels:  web-vitals
nuxt-speedkit
nuxt-speedkit will help you to improve the lighthouse performance score (100/100) of your website.
Stars: ✭ 401 (+289.32%)
Mutual labels:  web-vitals

Cover logo

Instant Vitals: Simple tools to track and improve your Web Vitals scores

npm (tag) npm (tag) GitHub

Instant Vitals is a tool for collecting Web Vitals metrics and storing them in Google BigQuery. The library has both a client and a server component. The client is responsible for collecting the metrics using web-vitals, which is maintained by the Google Chrome team, and sending the metrics to the endpoint of your choice. In addition to this, the client converts HTML elements into XPath query strings so that you can easily track down where your problems are later.

The server component is then used to take these metrics and send them to BigQuery. Once the metrics are in BigQuery, you can more easily query for the information you need to improve your Web Vitals scores.

For now we'll assume you're using npm and that you have some sort of build system in place for the client. While the server component is only available for NodeJS at the moment, this library is more of a pattern than a prescription so it shouldn't be too hard to implement this yourself in your language of choice.

Prerequisites

Instant Vitals relies on Google BigQuery to store and process data. You should create an account before getting started. Be aware that the paid tier is required to use this library; however, even with a large number of users, the cost should still be very low.

Once you have created an account, you will need to create a service account. The service account will need permission to create datasets and tables as well as insert records into the database. Create a key for this service account and keep it handy.

Client Installation

To get started, install the client library in your project:

npm i @instantdomain/vitals-client

Then, you can initialize the library in your browser code like so:

import { init } from "@instantdomain/vitals-client";

init({ endpoint: "/api/web-vitals" });

Here I'm using "/api/web-vitals" as the endpoint. You'll want to change this to an endpoint of your choice on a server that you control.

Server Installation

First, install the server library in your NodeJS project:

npm i @instantdomain/vitals-server

Then, you can initialize the server component. Here is an example request handler for the endpoint /api/web-vitals

import fs from "fs";

import { init, streamVitals } from "@instantdomain/vitals-server";

// Google libraries require service key as path to file
const GOOGLE_SERVICE_KEY = process.env.GOOGLE_SERVICE_KEY;
process.env.GOOGLE_APPLICATION_CREDENTIALS = "/tmp/goog_creds";
fs.writeFileSync(
  process.env.GOOGLE_APPLICATION_CREDENTIALS,
  GOOGLE_SERVICE_KEY
);

const DATASET_ID = "web_vitals";
init({ datasetId: DATASET_ID }).then().catch(console.error);

// Request handler
export default async (req, res) => {
  const body = JSON.parse(req.body);
  await streamVitals(body, body.name);
  res.status(200).end();
};

Note that here we are storing our Google Cloud service key as a string in GOOGLE_SERVICE_KEY. We then need to write the key to a temporary file before instructing the BigQuery library to read from that file.

Running

Once you start your server, you should see the requisite dataset and tables created in BigQuery. Once you have some visitors on your site, you should start seeing your Web Vitals metrics data in these tables:

BigQuery screenshot

Identifying opportunities for improvement

Now you're ready to identify some elements on your page that are causing issues. For example, you can query for CLS violations like so:

SELECT
  `vitalsdev.web_vitals.CLS`.Value,
  Node
FROM
  `vitalsdev.web_vitals.CLS`
JOIN
  UNNEST(Entries) AS Entry
JOIN
  UNNEST(Entry.Sources)
WHERE
  Node != ""
ORDER BY
  value
LIMIT
  10

This gives us the following result:

Value Node
4.6045324800736724E-4 /html/body/div[1]/main/div/div/div[2]/div/div/blockquote
7.183070668914928E-4 /html/body/div[1]/header/div/div/header/div
0.031002668277977697 /html/body/div[1]/footer
0.035830703317463526 /html/body/div[1]/main/div/div/div[2]
0.035830703317463526 /html/body/div[1]/footer
0.035830703317463526 /html/body/div[1]/main/div/div/div[2]
0.035830703317463526 /html/body/div[1]/main/div/div/div[2]
0.035830703317463526 /html/body/div[1]/footer
0.035830703317463526 /html/body/div[1]/footer
0.03988482067913317 /html/body/div[1]/footer

Now, you can browse to your website in Google Chrome and find the offending elements using the following code:

$x("/html/body/div[1]/main/div/div/div[2]/div/div/blockquote");

Page query example

As you can see, you can identify which elements on the page are degrading your CLS scores. Now you can use this information to improve your users' experiences and your Web Vitals scores!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].