Head Start provides a pre-configured setup for common assets like fonts and icons.
Astro copies all assets in public/
to the web root (dist/
). Using the public/
directory is suitable for static assets that don't require a build step and should be available as is. For example a some .wellknown
file.
Head Start uses the src/assets/
directory to organise raw assets that do require a build step. You are responsible for the processing and importing of these assets. Head Start provides a pre-configured setup for fonts and icons. These assets are eventually compiled to dist/_astro/
and are configured to be served with immutable cache headers for performance.
Head Start provides a setup for custom fonts to improve their loading performance. An example font (Archivo) is pre-configured in src/assets/fonts.ts
. To add your own custom fonts:
- Install the custom font. If it's an open source font, the easiest way is to install your custom font using Fontsource. Otherwise copy your custom font files (
woff2
) tosrc/assets/fonts/
manually. - Replace the example font imports in
src/assets/fonts.ts
with those of your custom fonts. - Replace the
const fonts
andconst fontsFamily...
values to match the name and variations of your custom fonts.
That's it. Head Start will now automatically preload the font files and include critical CSS for your custom fonts.
Head Start combines icons in a sprite and makes them available through the <Icon>
component. To use an icon:
- Add an SVG icon to
src/assets/icons/
. For example ashare.svg
icon. - Use the
Icon
component withname="share"
(SVG file basename):
---
import Icon from '@components/Icon/';
---
<Icon name="share">
<style>
/* optional: style on data attribute, or add a class */
[data-icon="share"] {
color: red;
}
</style>