Gathering detailed insights and metrics for webpack-font-preload-plugin
Gathering detailed insights and metrics for webpack-font-preload-plugin
Gathering detailed insights and metrics for webpack-font-preload-plugin
Gathering detailed insights and metrics for webpack-font-preload-plugin
npm install webpack-font-preload-plugin
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
20 Stars
121 Commits
10 Forks
3 Watching
5 Branches
3 Contributors
Updated on 10 Nov 2024
TypeScript (95.81%)
JavaScript (4.19%)
Cumulative downloads
Total Downloads
Last day
1.8%
16,646
Compared to previous day
Last week
4.3%
108,112
Compared to previous week
Last month
33.9%
428,716
Compared to previous month
Last year
93.6%
2,834,629
Compared to previous year
2
1
22
A webpack plugin to allow preloading or prefetching of fonts.
The preload value of the <link>
element's rel
attribute lets you declare fetch requests in the HTML's <head>
, specifying resources that your page will need very soon, which you want to start loading early in the page lifecycle, before browsers' main rendering machinery kicks in. This ensures they are available earlier and are less likely to block the page's render, improving performance.
This plugin specifically targets fonts used with the application which are bundled using webpack. The plugin would add <link>
tags in the begining of <head>
of your html:
1<link rel="preload" href="/font1.woff" as="font" crossorigin /> 2<link rel="preload" href="/font2.woff" as="font" crossorigin />
To begin, you'll need to install webpack-font-preload-plugin
:
1$ npm install webpack-font-preload-plugin --save-dev
Then add the plugin to your webpack
config. For example:
webpack.config.js
1const FontPreloadPlugin = require("webpack-font-preload-plugin"); 2 3module.exports = { 4 plugins: [new FontPreloadPlugin()], 5};
And run webpack
via your preferred method.
index
Type: string
Default: index.html
Optional: true
Name of the index file which needs modification.
1// in your webpack.config.js
2new FontPreloadPlugin({
3 index: "index.html",
4});
extensions
Type: string[]
Default: ['woff', 'woff2', 'ttf', 'eot']
Optional: true
Default font extensions which should be used.
1// in your webpack.config.js 2new FontPreloadPlugin({ 3 extensions: ["woff", "ttf", "eot"], 4});
crossorigin
Type: boolean
Default: true
Optional: true
Is the font request crossorigin or not.
1// in your webpack.config.js
2new FontPreloadPlugin({
3 crossorigin: true,
4});
loadType
Type: string
Default: preload
Optional: true
Type of load. It can be either preload
or prefetch
.
1// in your webpack.config.js
2new FontPreloadPlugin({
3 loadType: "preload",
4});
insertBefore
Type: string
Default: head > title
Optional: true
The selector for node before which the preload/prefetch links should be added.
1// in your webpack.config.js
2new FontPreloadPlugin({
3 // Add the preload statements before any other <link> tag present in html
4 insertBefore: "head > link:nth-child(1)",
5});
replaceCallback
Type: Function
Default: undefined
Optional: true
Callback for doing custom manipulations to index.html for special use cases like templating or server side rendering. This callback would be passed an object
as parameter with 2 keys:
indexSource
: Full source string of the index.html.linksAsString
: <link>
tags for preloading fonts as a string.The consuming app can use this information to generate the final index.html and must return an updated string which would be used as index.html after webpack build.
1// in your webpack.config.js 2new FontPreloadPlugin({ 3 replaceCallback: ({ indexSource, linksAsString }) => { 4 return indexSource.replace("{{{links}}}", linksAsString); 5 }, 6});
filter
Type: string
Default: undefined
Optional: true
Expression for allowing more granular filtering of the font assets for doing a preload/prefetch. The filter is applied on the font assets selected by the extensions
option. If the filter is a string, all the font assets which contain the string as part of the name are included in the preload and rest are ignored. In case filter is regex, the font asset's name is tested to match the regex for allowing preload. If you don't pass this option, all the font assets will be preloaded.
1// To only preload font's which have string `app-font` as part of there name.
2new FontPreloadPlugin({
3 filter: "app-font",
4});
5
6// To preload fonts which start with `mui` or `app` in there name.
7new FontPreloadPlugin({
8 filter: /^mui|^app/i,
9});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 0/4 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
17 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More