Skip to content

Demo

astro-page-insight

docs | demo

This is an Astro integration that shows everything to improve from Lighthouse results directly on the page.

[!IMPORTANT] This result is by dev mode, so it may not be accurate.
Especially, the Score is not accurate.

Usage

Prerequisites

Astro 4.0 or later is required.

Installation

Install the integration automatically using the Astro CLI:

Terminal window
pnpm astro add astro-page-insight
Terminal window
npx astro add astro-page-insight
Terminal window
yarn astro add astro-page-insight

Or install it manually:

  1. Install the required dependencies
Terminal window
pnpm add astro-page-insight
Terminal window
npm install astro-page-insight
Terminal window
yarn add astro-page-insight
  1. Add the integration to your astro config
import pageInsight from "astro-page-insight";
export default defineConfig({
integrations: [
pageInsight(),
],
});

Configuration

Here is the options:

PropertyTypeDefaultDescription
lh.weightnumber0weight is the threshold value in the audit.
lh.breakPointnumber767breakPoint is used to determine whether on mobile or desktop.
firstFetchload, open, nonenonefirstFetch is used for when to do the first fetch.
if firstFetch is load, will fetch on page load.
if firstFetch is open, will fetch on first app open.
if firstFetch is none, only fetch on user interaction.
cachebooleanfalsecache is used to enable the cache.
if cache is true, will enable to cache the lighthouse report.
build.bundlebooleanfalsebundle is used to determine whether to bundle the page insight.
if bundle is true, will bundle the page insight. so you can see the insight after build.
It will bundle results from local cache.
build.showOnLoadbooleanfalseshowOnLoad is used to determine whether to show the page insight on page load.
if showOnLoad is true, will show the page insight on page load.

Example

import pageInsight from "astro-page-insight";
export default defineConfig({
integrations: [
pageInsight({
lh: {
weight: 0.5,
breakPoint: 1024,
},
firstFetch: "open",
cache: true,
build: {
bundle: true, // You should get value from the environment variable. (e.g. process.env.STAGING === "true")
showOnLoad: true, // This option is only available when `bundle` is `true`.
},
}),
],
});

gitignore

If you want to ignore the cache, add the following to your .gitignore:

.pageinsight

Notification

You can sometimes see that the notification is displayed in the app.
There are three types of notifications:

ColorDescription
Blueblue means that results are fresh.
Yellowyellow has two meanings.
One is that the results are from the cache.
The other is that fetching is in progress.
Redred means that fetching failed.

build.bundle

If you set build.bundle to true, It will bundle results from local cache, So you need to have lighthouse results(cache) on build time.

Contributing

This package is structured as a monorepo:

  • playground contains code for testing the package
  • package contains the actual package

Install dependencies using pnpm:

Terminal window
pnpm i --frozen-lockfile

Watch for package changes:

Terminal window
pnpm package:dev

Start the playground with blog:

Terminal window
pnpm playground:blog

Start the playground with ssr:

Terminal window
pnpm playground:ssr

Start the playground with starlog:

Terminal window
pnpm playground:starlog

You can now edit files in package. Please note that making changes to those files may require restarting the playground dev server.

Licensing

MIT Licensed. Made with ❤️ by ktym4a.