-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76455f9
commit 01fd503
Showing
22 changed files
with
2,414 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
404.html,1660355774737,daa499dd96d8229e73235345702ba32f0793f0c8e5c0d30e40e37a5872be57aa | ||
script2.js,1660353082942,9fc61023c132f480ca8aa2a15020d9862c7cd033b30c3f16388e0f665a60da67 | ||
test/index.html,1660352552045,b58c96ffe52a79ef1155e535d83e2257b2ed754560655bcaa7dbb5b68f4ba344 | ||
flamethrower.js,1660363180345,6797435a47b62827ba28aeb8ebecc76a2d2091c8fdc58ed05c9a0832fbecaf70 | ||
about/index.html,1660357528355,ea2005a3fc92e245a65f1a0d30ba01676d8749adb7e344bb184d468f48571ef1 | ||
index.html,1660362476397,4cc7813b8344667d071d2ab4917aab4edb9afe35807c079a130739a8e2ff5df8 | ||
script1.js,1660359863695,ca7ea3da9b13b2e2020d80b214e17088649042a64053aa78966395e8637674d7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2021 Fireship LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,88 @@ | ||
|
||
# Flamethrower 🔥 | ||
|
||
## | ||
Status: Meme | ||
|
||
- Scripts inside the body tag will always run. | ||
- Scripts in the head will only run | ||
An 1.5kB zero-config router and prefetcher that makes static sites feel like a blazingly fast SPA. | ||
|
||
## Why? | ||
|
||
**Problem** Static sites cannot easily share state between pages. This makes it hard to create a good UX with JavaScript libraries because each new page needs to reboot your JS from scratch. | ||
|
||
## How? | ||
|
||
1. It tells the browser to prefetch links in the current page. | ||
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-exectute 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 | ||
``` | ||
|
||
```js | ||
import flamethrower from 'flamethrower'; | ||
const router = flamethrower(); | ||
``` | ||
|
||
That's it. Your site now feels blazingly fast. | ||
|
||
|
||
## Advanced Usage | ||
|
||
```js | ||
// with opts | ||
const router = flamethrower({ prefetch: true, log: false, pageTransitions: false }); | ||
|
||
// Navigate manually | ||
router.go('/somewhere'); | ||
router.back(); | ||
router.forward(); | ||
|
||
// Listen to events | ||
window.addEventListener('router:fetch', showLoader); | ||
window.addEventListener('router:end', hideLoader); | ||
|
||
// Disable it | ||
router.enabled = false; | ||
``` | ||
|
||
Opt-out of specific links for full page load. | ||
|
||
```html | ||
<a href="/somewhere" data-cold></a> | ||
``` | ||
|
||
Force scripts in the head to run. | ||
|
||
```html | ||
<script src="..." data-reload></script> | ||
``` | ||
|
||
If using Google Analytics, events will need to be sent manually, i.e: | ||
|
||
```js | ||
window.addEventListener('router:end', (e) => { | ||
const page_path = new URL(window.history.state['url']).pathname; | ||
gtag('config', 'UA-YOUR_ID', { page_path }); | ||
}); | ||
``` | ||
|
||
### Misc | ||
|
||
**Supported in all browsers?** Yes. It will fallback to standard naviation 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](https://github.com/hotwired/turbo) Drive, just much lighter. | ||
- Google analytics will not be updated on page change, you'll need to listen to `router:end` and send the GA event manually. | ||
- This project is experimental. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Page Not Found</title> | ||
|
||
<style media="screen"> | ||
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; } | ||
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; } | ||
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; } | ||
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; } | ||
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;} | ||
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; } | ||
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; } | ||
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); } | ||
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; } | ||
@media (max-width: 600px) { | ||
body, #message { margin-top: 0; background: white; box-shadow: none; } | ||
body { border-top: 16px solid #ffa100; } | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="message"> | ||
<h2>404</h2> | ||
<h1>Page Not Found</h1> | ||
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p> | ||
<h3>Why am I seeing this?</h3> | ||
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.