Progress Bar: Page One
This page shows a custom progress bar based on an idea by @kb↗. It utilizes the swup progress bar plugin↗. Click on the link to page two a above this section to see it in action.
Install the 👜 Bag of Tricks ✨ in your astro project with npm install astro-vtbot
or install as an Astro integration!. Then use the <ProgressBar>
like this:
---import BrakePad from 'astro-vtbot/components/BrakePad.astro';import ProgressBar from 'astro-vtbot/components/ProgressBar.astro';import MdxLayout from './MdxLayout.astro';---
<MdxLayout {...Astro.props}> { /* This is the custom component. * It can be put into the <head> or the <body> of your page */ } <ProgressBar />
{/* To observe the effect in DEV mode it is necessary to simulate 2000ms loading time */} <BrakePad duration={2000} />
<slot /></MdxLayout>
{/* You can style the progress bar by defining the swup-progress-bar class */}<style is:global> .swup-progress-bar { background-color: rgb(64, 128, 192); }</style>
The <BrakePad />
component shown in the listing above is optional. It helps you to see the progress bar even if you have a fast server and a fast connection: It simulates long loading times for DEV mode. <BrakePad />
does nothing when you build for production.
As an alternative you could also throttle the connection speed using the browser’s dev tools.