Nuxt Speedkit takes over the Lighthouse performance optimization of your generated website. All used components and resources are loaded on demand based on the viewport.
Features:
- automatic preloading critical font resources
- dynamic viewport based loading of font resources (subselectors, media queries)
- dynamic loading of images based on bandwidth
Result:
- delivery of the minimum required resources based on the current viewport
![]() IE / Edge |
![]() Firefox |
![]() Chrome |
![]() Safari |
![]() iOS Safari |
![]() Samsung |
![]() Opera |
![]() Vivaldi |
---|---|---|---|---|---|---|---|
Edge | last 2 versions | last 2 versions | last 2 versions | last 2 versions | last 2 versions | last 2 versions | last 2 versions |
- Add
nuxt-speedkit
dependency to your project.
npm run add nuxt-speedkit # or npm install nuxt-speedkit
- Add
nuxt-speedkit
to themodules
section ofnuxt.config.js
.
{
modules: [
// Simple usage
'nuxt-speedkit',
// With options
['nuxt-speedkit', {
fonts: [{
family: 'Font A',
fallback: ['Arial', 'sans-serif'],
variance: [
{
style: 'normal',
weight: 300,
src: '@/assets/fonts/font-a-300'
}, {
style: 'italic',
weight: 300,
src: '@/assets/fonts/font-a-300Italic'
}, {
style: 'normal',
weight: 400,
src: '@/assets/fonts/font-a-regular'
}, {
style: 'italic',
weight: 400,
src: '@/assets/fonts/font-a-regularItalic'
}, {
style: 'normal',
weight: 700,
src: '@/assets/fonts/font-a-700'
}, {
style: 'italic',
weight: 700,
src: '@/assets/fonts/font-a-700Italic'
}
]
}]
}]
]
}
Property | Type | Description | Default |
---|---|---|---|
fonts |
Array |
List of included fonts. | [] |
componentAutoImport |
Boolean |
If set Component automatically import from module. | [] |
componentPrefix |
String |
Defines a prefix for the module components, important for auto import (componentAutoImport ). E.g.: LazyPicture -> PrefixLazyPicture |
[] |
Property | Type | Description | Default |
---|---|---|---|
family |
String |
Font-Family Name | undefined |
fallback |
Array |
Fallback fonts e.g. ['Arial', 'sans-serif'] |
undefined |
variance |
Array |
List of font variances | [] |
Property | Type | Description | Default |
---|---|---|---|
style |
String |
CSS-Prop. font-style |
undefined |
weight |
String |
CSS-Prop. font-weight |
undefined |
src |
String |
File Path without extension. require path available. |
[] |
The use of the components is default lazy
.
lazy
components are activated by IntersectionObserver.
If you use the attribute critical
, the components switch to eager
.
It is recommended that you declare components visible in the initial viewport with critical
.
Any Vue component can be set with the attribute critical
.
Important critical
option is inherited on child nodes.
When using slot
and v-font
on a component set directly with critical
, the font must be set as critical
separately via isCritical.
LazyIframe [code]
Use native attributes to configure iframe (eg. <iframe>
).
<lazy-iframe src="β¦" />
LazyImage [code]
Use native attributes to configure image (eg. <img>
).
Do not use the
loading
attribute, this will break the LazyLoad mechanism.
<lazy-image src="β¦" />
LazyPicture [code]
Use native attributes to configure picture (eg. <picture>
).
<lazy-picture src="β¦" />
{
alt: 'β¦', // Image alt
title: 'β¦', // Image Title
sources: [
{
// srcset can be filled with additional objects for different densities.
srcset: [
{
url: 'β¦', // File path
density: undefined// Value for density eg. 1x, 2x, by default not set.
}
],
type: // mimetype
}
]
}
Use critical
to switch the component contained in the module or $getFont to eager
.
Attribute
<!-- use default attribute -->
<lazy-picture src="β¦" critical/>
<!-- use boolean -->
<lazy-picture src="β¦" :critical="true"/>
Single File Example
<template>
<div>
<span v-font="$getFont(β¦)"></span>
</div>
</template>
<script>
export default {
critical: true,
props: { β¦ }
}
</script>
For using the v-font
directive, you can use $getFont
to register a font on the current node.
By multiple Fonts Variants you can set a array.
Single Variance
<node v-font="$getFont(β¦)">β¦
Multiple Variance
<node v-font="[$getFont(β¦).bySelector('b,strong'), $getFont(β¦).bySelector('i')]">β¦
When registering the font with $getFont, a font object is returned.
This can be used to restrict the font to selectors (bySelector
) or set as critical (isCritical
).
Parameters
Property | Value | Default |
---|---|---|
family | Font-Family (eg. Custom Font ) |
required |
weight | Font-Weight (eg. 700 ) |
400 |
style | Font-Style (eg. italic ) |
normal |
$getFont
returns a FontObject
, with these can be used for other operations.
Return: FontObject
Sets the font as critical. Use critical for Font, that you see in the initial viewport.
Other fonts load by lazyload, when show in viewport.
<node v-font="$getFont(β¦).isCritical()">β¦
β οΈ Font preload not supported orientation media query. e.g.(orientation: portrait)
Font load and show by current CSS Media Query.
Ideal for Viewport optimized font load.
<node v-font="$getFont(β¦).isCritical().addMedia('(min-width: 992px)')">β¦
β οΈ Order must be respected when using selectors. CSS Specificity
Return: FontObject
Defines css selectors to which the font should be applied.
<node v-font="$getFont(β¦).bySelector('strong')">β¦
OR operators can be defined by string or array.
<!-- String -->
<node v-font="$getFont(β¦).bySelector('strong,i')">β¦
<!-- Array -->
<node v-font="$getFont(β¦).bySelector('strong', 'i')">β¦
β¦
- add critical images as preload
- merge fontTools into font classes
- check: convert html scripts into dynamic imports -> better & stable load performance
- rename package
- add package logo
- Complete readme
- Cross Browser (IE Edge, Firefox, Chrome, Edge, Safari)
- Live example website (eg. grabarzundpartner.de)
- Example/Test pages
- Create jest test based on test pages
- v-font
- LazyImage
- LazyPicture
- LazyIframe
- LazyVideo
- Clean Up!
- Namings
- code optimization
- Publish module (npm, nuxt-modules)
- vFont-Collector as standalone vue plugin
- Documentation and preparation for video streaming with LazyVideo
- IE 11 (FontFace): https://github.com/bramstein/fontloader
- Cypress visual regression tests
- Clone this repository
- Install dependencies using
npm run install
ornpm install
- Start development server using
npm run dev
- Clone this repository
- Install dependencies using
npm run install
ornpm install
- Build and start with express
npm run start:generate
- Open http://127.0.0.1:3000 in Browser.
or look here