• Stars
    star
    2,771
  • Rank 16,030 (Top 0.4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A blazingly fast router for static sites

Flamethrower πŸ”₯

Status: Meme

A 2kB zero-config router and prefetcher that makes a static site feel like a blazingly fast SPA.

Why?

Problem: Static sites feel slow and cannot easily share state between pages. This makes it difficult to create a pleasant user experience (UX) with JavaScript libraries because each new page needs to reboot your JS from scratch.

Rather than requiring a frontend framework to take control of the entire DOM, the goal is to make route changes on static sites feel faster, like a SPA.

How?

  1. It tells the browser to prefetch visible links in the current page with IntersectionObserver.
  2. Intercepts click and popstate events, then updates the HTML5 history on route changes.
  3. Uses fetch to get the next page, swaps the <body> out, merges the <head>, but does not re-execute head scripts (unless asked to).

This means you can have long-lived JavaScript behaviors between navigations. It works especially well with native web components.

QuickStart

npm i flamethrower-router
import flamethrower from 'flamethrower-router';
const router = flamethrower();

That's it. Your site now feels blazingly fast.

Advanced Usage

// with opts
const router = flamethrower({ prefetch: 'visible', log: false, pageTransitions: false });

// Navigate manually
router.go('/somewhere');
router.back();
router.forward();

// Listen to events
window.addEventListener('flamethrower:router:fetch', showLoader);
window.addEventListener('flamethrower:router:fetch-progress', updateProgressBar);
window.addEventListener('flamethrower:router:end', hideLoader);

// Disable it
router.enabled = false;

Opt-out of specific links for full page load.

<a href="/somewhere" data-cold></a>

Scripts in <body> will run on every page change, but you can force scripts in the <head> to run:

<script src="..." data-reload></script>

The fetch-progress event is a custom event, so usage will look something like this:

window.addEventListener('flamethrower:router:fetch-progress', ({ detail }) => {
	const progressBar = document.getElementById('progress-bar');
	// progress & length will be 0 if there is no Content-Length header
	const bytesReceived = detail.received; // number
	const length = detail.length; // number
	progressBar.style.width = detail.progress + '%';
});

Prefetching

Prefecthing is disabled by default.

  • visible: prefetch visible links on the page with IntersectionObserver
  • hover: prefetch links on hover
const router = flamethrower({ prefetch: 'visible' });

Misc

Supported in all browsers? Yes. It will fallback to standard navigation if window.history does not exist.

Does it work with Next.js? No, any framework that fully hydrates to an SPA does not need this - you already have a client-side router.

Does it work with Astro? I think so. It can share state between routes, but partially hydrated components may flash between routes.

Other things to know:

  • <head> scripts run only on the first page load. <body> scripts will still run on every page change (by design).
  • It's a good idea to show a global loading bar in case of a slow page load.
  • This library is inspired by Turbo Drive.
  • This project is experimental.

Contributing

Build it:

npm run dev

Serve the example:

npm run serve

Make sure all playwright tests pass before submitting new features.

npm run test

Deploying

You can deploy Flamethrower to Vercel as follows:

npm run deploy

This uses the Build Output API and the Vercel CLI to deploy the /example folder.

More Repositories

1

fireship.io

Build and ship your app faster https://fireship.io
Svelte
3,376
star
2

threejs-scroll-animation-demo

3D Scrolling Portfolio Website with Three.js
HTML
1,414
star
3

react-firebase-chat

JavaScript
809
star
4

222-responsive-icon-nav-css

A Simple Responsive Animated CSS Icon Navbar
HTML
691
star
5

tailwind-dashboard

Discord inspired dashboard built with Tailwind CSS and React
JavaScript
584
star
6

229-multi-level-dropdown

Build an animated multi-level dropdown inspired by Facebook's UI
JavaScript
551
star
7

flutter-firebase-quizapp-course

QuizApp Built with Flutter & Firebase
Dart
541
star
8

webrtc-firebase-demo

Video Chat with WebRTC and Firebase
JavaScript
484
star
9

node-blockchain

Blockchain Cryptocurrency Implemented with Node & TypeScript
TypeScript
473
star
10

gpt3-twitter-bot

Build a GPT-3 Powered Twitter Bot with Node.js & Firebase
JavaScript
470
star
11

next-firebase-course

Next.js + Firebase - The Full Course
JavaScript
467
star
12

gun-chat

Decentralized Chat App with Gun.js
JavaScript
442
star
13

10-javascript-frameworks

Comparison of 10 frontend JavaScript frameworks
TypeScript
431
star
14

node-crypto-examples

7 Useful Examples of Cryptography in Node.js
JavaScript
375
star
15

nft-art-generator

A simple randomized NFT art generator
JavaScript
369
star
16

cramer-algo-trader

Trade Stocks with Node.js, Alpaca, and GPT-3
JavaScript
291
star
17

223-electron-screen-recorder

Episode 223 - Build a Screen Recorder with Electron
JavaScript
275
star
18

next13-pocketbase-demo

Demo for the new Next.js 13 features with Pocketbase.
CSS
265
star
19

sorting-algorithms

A collection of sorting algorithms implemented in JS
JavaScript
265
star
20

javascript-millionaire

Who wants to be a JavaScript Millionaire terminal game
JavaScript
245
star
21

224-animated-css-grid

Episode 224 - Build Three CSS Grid Layouts from Scratch
HTML
243
star
22

git-sticker

submit pull request, git free sticker πŸ”₯
JavaScript
233
star
23

web3-nft-dapp-tutorial

A simple web3 app for minting NFTs
JavaScript
222
star
24

stripe-payments-js-course

Fullstack Stripe Payments for the JavaScript Developer
TypeScript
211
star
25

wavy-curvey-blobby-website

A website design with lots of waves, curves, a blobs
HTML
198
star
26

stacked-card-list

Stacked Card List Demo
HTML
189
star
27

animated-svg-demo

SVG + CSS Animation Tutorial
HTML
188
star
28

225-github-actions-demo

Episode 225 - Setup CI/CD with Github Actions
HTML
171
star
29

socketio-minimal-demo

Minimal socket.io group chat demo
JavaScript
165
star
30

react-wasm-gif-maker

Video to GIF with WASM (FFpeg) & React
JavaScript
161
star
31

pocketchat-tutorial

A basic realtime chat app with Pocketbase and Svelte
Svelte
161
star
32

fkit-course

The Full SvelteKit Course
Svelte
159
star
33

angular-tic-tac-toe

Angular Tic-Tac-Toe - A Tutorial for Beginners
TypeScript
145
star
34

javascript-course

JavaScript - The Full Course
JavaScript
143
star
35

this-video-has-n-views

Use the YouTube API to update a video title
JavaScript
143
star
36

226-css-theme-toggler

Episode 226 - Build a CSS Theme Toggler from Scratch
HTML
136
star
37

api-monetization-demo

Build a Monetized API with Stripe Metered Billing
JavaScript
135
star
38

skydiving-cat-parallax

React Spring Parallax Demo
JavaScript
129
star
39

7-pwa-features-demo

Seven web-platform features you didn't know existed.
JavaScript
124
star
40

nextjs-course

Next.js Full Course
TypeScript
116
star
41

nextjs-basics

Next.js in 100 Seconds Demo Code
JavaScript
103
star
42

3.1-firebase-basics

Firebase - The Basics
JavaScript
96
star
43

192-flutter-fcm-push-notifications

Episode 192 - Flutter Firebase Cloud Messaging Guide
Dart
95
star
44

tdd-basics-project

Implement a JS Stack with TDD
JavaScript
93
star
45

framer-demo

Framer motion demo with React
JavaScript
89
star
46

flutter-firebase-course

QuizApp Built with Flutter & Firebase
Dart
89
star
47

182-svelte-firebase

Episode 182 - Svelte 3 + RxFire
JavaScript
84
star
48

230-animated-form-password-meter

Animated Form w/ Password Strength Meter
HTML
79
star
49

fireship-quizapp-data

A node script to populate Firestore with quiz questions
JavaScript
79
star
50

redis-nextjs-fulltext-search

Instant Fulltext Search with Redis & Next.js
JavaScript
76
star
51

react-course

React - The Full Course
JavaScript
69
star
52

invite-only-phone-auth

Invite-Only FOMO Auth with React & Firebase
JavaScript
68
star
53

docker-nodejs-basic-demo

A simple demo running Node.js on Docker
JavaScript
67
star
54

175-code-this-not-that-rxjs

Episode 175 - Code This, Not That. RxJS.
JavaScript
66
star
55

google-sheets-database

Google Sheets as a Database - Next.js Demo
JavaScript
63
star
56

193-paypal-checkout-v2-demos

Episode 193 - PayPal Checkout with Angular, React, and Vue
TypeScript
62
star
57

183-flutter-draggable-game

Episode 183 - Build a simple Drag-and-Drop kid's game with Flutter
Dart
60
star
58

supaship.io

HTML
59
star
59

firechat-react-native

Firebase chat app built with React Native
JavaScript
55
star
60

185-advanced-flutter-firestore

Episide 185 - Advanced Techniques for working with data in Firebase & Flutter
Dart
55
star
61

174-flutter-firestore-animated-slideshow

Episode 174 - Animated Slideshow Inspired by Reflectly
Dart
53
star
62

firechat-flutter

Firebase chat app made with Flutter
Dart
53
star
63

vue-firebase-walkie-talkie

Build a walkie-talkie style chat app with Vue & Firebase
Vue
50
star
64

167-flutter-geolocation-firestore

Episode 167 - Realtime Geolocation with Flutter, Google Maps, and Firestore
Dart
50
star
65

nodejs-typescript-starter

A very basic starter for Node.js + TypeScript
TypeScript
48
star
66

202-chatbot-dialogflow

Episode 202 - Build a chatbot with Dialogflow, Cloud Functions, and Angular
TypeScript
48
star
67

rust-in-100

Rust in 100 seconds, potentially and beyond!
Rust
47
star
68

198-web-scraper-link-preview

TypeScript
46
star
69

coinbase-cloud-functions

Coinbase + Firebase Cloud Functions Demo
JavaScript
46
star
70

fire-baseline

Baseline setup for Firebase in common frontend frameworks
TypeScript
46
star
71

flutter-base

Base app for Flutter + Firebase Lessons
Dart
45
star
72

170-flutter-animated-radial-menu

Episode 170 - Build an Animated Radial Menu from Scratch
Dart
43
star
73

stripe-for-saas

Stripe Course for Software-as-a-Service App Developers
TypeScript
41
star
74

169-pwa-trusted-web-activity

Episode 169 - Deploy a PWA to as an Android Package to the Google Play Store
Shell
40
star
75

firebase-security-course

Master Firebase Security Rules
JavaScript
34
star
76

dart-course

Master the Basics of the Dart Language
Dart
33
star
77

177-flare-flutter-giphy-navbar

Episode 177 - Giphy-inspired navbar with Flutter & Flare
Dart
32
star
78

213-deckgl-google-maps

Episode 213 - Visualize large datasets on Google Maps with deck.gl
JavaScript
31
star
79

171-stripe-elements-angular

Stripe Elements and Checkout in Angular
TypeScript
29
star
80

199-flutter-firebase-storage-uploads

Episode 199 - Capture Files in Flutter and Upload to Firebase Storage
Dart
26
star
81

214-flutter-binary-clock

A Binary #FlutterClock
Dart
26
star
82

nest-cloud-functions

NestJS + Firebase Cloud Functions Example
TypeScript
26
star
83

faunadb-basics

Build a simple API with FaunaDB and Node.js
JavaScript
26
star
84

168-multi-file-upload-angular-firebase

Episode 168 - Upload Multiple Files Concurrently to Firebase Storage
TypeScript
26
star
85

multifactor-auth-firebase

Implement 2FA or Multifactor Auth with SMS Text Verification
JavaScript
25
star
86

196-sendgrid-email-cloud-functions

Episode 196 - Send Transactional with SendGrid and Cloud Functions
TypeScript
24
star
87

165-angular-router-animations

Episode 165 - A Complete Guide to Angular Router Animations
TypeScript
24
star
88

55-angularfire-google-auth

Episode 55 (Revised) - Firebase Google OAuth with @angular/fire + Firestore
TypeScript
23
star
89

188-firebase-vs-amplify

Episode 188: Comparison of Firebase to AWS Amplify
JavaScript
21
star
90

nuxt3-firebase-starter

Basics SSR and Hydration with Nuxt3 and Firebase
Vue
21
star
91

code-this-not-that-python-edition

10 tips to make your code more Pythonic
Python
19
star
92

181-cloud-functions-task-queue

Episode 181 - Schedule dynamic background jobs with Firebase Cloud Functions & Firestore
TypeScript
19
star
93

203-algolia-firestore-mvp

Episode 203 - Full-text Search with Algolia
TypeScript
19
star
94

216-flutter-ipod

Episode 216 - Build the Classic iPod UI with Flutter
Dart
19
star
95

201-cloud-functions-sql-typeorm

Episode 201 - MySQL & TypeORM with Firebase Cloud Functions
TypeScript
18
star
96

159-angular-universal-cloud-functions

Episode 159 - Deploy Angular Universal to Firebase Cloud Functions or AppEngine
TypeScript
18
star
97

d3-firebase-demo

Build a bar chart using a Vite Vanilla JS project with D3 and Firestore
JavaScript
18
star
98

meilisearch-firebase

Run MeiliSearch on Firebase & Google Cloud
JavaScript
17
star
99

212-stripe-svelte

Use Stripe Payments in Svelte
HTML
16
star
100

147-cloud-build-firebase

Episode 147 - Continuous Integration and Delivery with Cloud Build + Firebase
JavaScript
15
star