preload-links-by-lighthouse
v0.1.0
Published
Generate html with embedded preload links using lighthouse
Downloads
0
Maintainers
Readme
preload-links-by-lighthouse
Generate html with embedded preload links using lighthouse
Installation
$ npm i @mizdra/preload-links-by-lighthouse
Usage
import { auditNetworkRequest, filterByScript, generatePreloadLinks } from '@mizdra/preload-links-by-lighthouse';
(async () => {
const networkRecords = await auditNetworkRequest('https://web.dev/', {
// pass the lighthouse options (optional)
logLevel: 'info',
});
const filteredNetworkRecords = networkRecords.filter(filterByScript);
const html = generatePreloadLinks({ networkRecords: filteredNetworkRecords });
console.log(html);
// output:
// <link rel="preload" href="https://web.dev/js/app.js?v=1d84cab8" as="script">
// <link rel="preload" href="https://web.dev/js/default.js?v=d79b36fb" as="script">
// <link rel="preload" href="https://www.google-analytics.com/analytics.js" as="script">
// <link rel="preload" href="https://web.dev/js/index-725dce56.js" as="script">
// <link rel="preload" href="https://web.dev/js/actions-2a4a4fee.js" as="script">
// <link rel="preload" href="https://www.gstatic.com/firebasejs/6.6.1/firebase-app.js" as="script">
// <link rel="preload" href="https://www.gstatic.com/firebasejs/6.6.1/firebase-auth.js" as="script">
// <link rel="preload" href="https://www.gstatic.com/firebasejs/6.6.1/firebase-performance.js" as="script">
})().catch((err) => {
console.error(err);
process.exit(1);
});
Examples
See examples/.
For Maintainers
How to dev
yarn run start
: Run for productionyarn run build
: Build for productionyarn run dev
: Run for developmentyarn run check
: Try static-checking
How to release
$ # Wait for passing CI...
$ git switch master
$ git pull
$ yarn version
$ rm -rf dist && yarn run build
$ npm publish
$ git push --follow-tags