Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #36 from weebney/fix-unhandled-exception
Browse files Browse the repository at this point in the history
Fix unhandled exception in text node edge case
  • Loading branch information
weebney authored Apr 25, 2023
2 parents e2106a8 + 40dbe07 commit 29a9290
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/content/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ In the above demo, the time "saved" refers to time that would have been wasted w

## Using Tachyon

<span id="copyText" style="inline-size: min-content;overflow-wrap: break-word;">`<script src="https://unpkg.com/[email protected].0/tachyon.min.js" integrity="sha384-w8efYzZSanBkhmSezV71UPT1uzvN9Ecr4ehP5gizbGl1esC0V/+2w7lqiT6FkUOe" type="module" crossorigin defer></script>`</span>
<span id="copyText" style="inline-size: min-content;overflow-wrap: break-word;">`<script src="https://unpkg.com/[email protected].1/tachyon.min.js" integrity="sha384-4iJteL1FYnj4Ju83AJvNthpx5gZ1QaXCamXhY3lxhAjTNXUN+NXq5LQV/fXOSRme" type="module" crossorigin defer></script>`</span>

<div style="text-align:right;">
<button id="copier">
Expand Down Expand Up @@ -113,7 +113,7 @@ Tachyon could be considered an alternative to projects like [instant.page](https
</tr>
<tr>
<td>Size</td>
<td><b>723 b</b></td>
<td><b>738 b</b></td>
<td>3.14 kb<br>(4.3x larger)</td>
<td>60.1 kb<br>(83x larger)</td>
<td>111 kb<br>(153x larger)</td>
Expand Down
2 changes: 1 addition & 1 deletion docs/content/cms/copy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const codeBlock = document.getElementById("codeBlock")
const copyButton = document.getElementById("copier")

codeBlock.innerText = '<script src="https://unpkg.com/[email protected].0/tachyon.min.js" integrity="sha384-w8efYzZSanBkhmSezV71UPT1uzvN9Ecr4ehP5gizbGl1esC0V/+2w7lqiT6FkUOe" type="module" crossorigin defer></script>';
codeBlock.innerText = '<script src="https://unpkg.com/[email protected].1/tachyon.min.js" integrity="sha384-4iJteL1FYnj4Ju83AJvNthpx5gZ1QaXCamXhY3lxhAjTNXUN+NXq5LQV/fXOSRme" type="module" crossorigin defer></script>';

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
Expand Down
7 changes: 4 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Easy Setup Instructions:
</tr>
<tr>
<td>Size</td>
<td><b>723 b</b></td>
<td><b>738 b</b></td>
<td>3.14 kb<br>(4.3x larger)</td>
<td>60.1 kb<br>(83x larger)</td>
<td>111 kb<br>(153x larger)</td>
Expand Down Expand Up @@ -75,7 +75,7 @@ Easy Setup Instructions:
Using Tachyon is unbelieveably easy. If you're not using node, you can just include it via script tags. Provided below is the script hosted by [unpkg](https://unpkg.com/). The source itself lives in the [tachyon directory](https://github.com/weebney/tachyon/tree/main/tachyon).

```html
<script src="https://unpkg.com/[email protected].0/tachyon.min.js" integrity="sha384-w8efYzZSanBkhmSezV71UPT1uzvN9Ecr4ehP5gizbGl1esC0V/+2w7lqiT6FkUOe" type="module" crossorigin defer></script>
<script src="https://unpkg.com/[email protected].1/tachyon.min.js" integrity="sha384-4iJteL1FYnj4Ju83AJvNthpx5gZ1QaXCamXhY3lxhAjTNXUN+NXq5LQV/fXOSRme" type="module" crossorigin defer></script>
```

If you look on the website, there are also easy install instructions for [Google Tag Manager](https://fasterthanlight.net/#easy-setup-instructions), [Shopify](https://fasterthanlight.net/#easy-setup-instructions), [WordPress](https://fasterthanlight.net/#easy-setup-instructions), and more.
Expand All @@ -91,7 +91,8 @@ npm i tachyonjs
Tachyon is super tiny, so you can also inline it. If you use the following inlined `<script>` tags, you are waived from the legal requirement to include a copy of the license.

```html
<script type="module" defer>/* tachyon 2.0.0 */var e=document.body.dataset;const o="tachyonWhitelist"in e,n="tachyonSameOrigin"in e,a=e.tachyonTimer||50;let r=null;function i(){r=r?null:this;const t="tachyon";var e=document.getElementById(t);e?e.remove():setTimeout(()=>{var e;r===this&&((e=document.createElement("link")).id=t,e.href=this.href,e.rel="prerender",document.head.appendChild(e))},a)}function t(t){var e="tachyon"in t.dataset;"A"!==t.tagName||!t.href||e!=o&&!n||n&&!e&&t.origin!==window.location.origin||["mouseover","mouseout","touchstart","touchend"].forEach(e=>t.addEventListener(e,i,{passive:!0}))}new MutationObserver(e=>e.forEach(e=>e.addedNodes.forEach(t))).observe(document.body,{childList:!0,subtree:!0}),document.querySelectorAll("a").forEach(t);</script>
<script type="module" defer>/* tachyon 2.0.1 */var e=document.body.dataset;const o="tachyonWhitelist"in e,n="tachyonSameOrigin"in e,a=e.tachyonTimer||50;let r=null;function i(){r=r?null:this;const t="tachyon";var e=document.getElementById(t);e?e.remove():setTimeout(()=>{var e;r===this&&((e=document.createElement("link")).id=t,e.href=this.href,e.rel="prerender",document.head.appendChild(e))},a)}function t(t){var e;t.dataset&&(e="tachyon"in t.dataset,"A"!==t.tagName||!t.href||e!=o&&!n||n&&!e&&t.origin!==window.location.origin||["mouseover","mouseout","touchstart","touchend"].forEach(e=>t.addEventListener(e,i,{passive:!0})))}new MutationObserver(e=>e.forEach(e=>e.addedNodes.forEach(t))).observe(document.body,{childList:!0,subtree:!0}),document.querySelectorAll("a").forEach(t);
</script>
```

### Configuration
Expand Down
6 changes: 3 additions & 3 deletions tachyon/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "tachyonjs",
"version": "2.0.0",
"description": "Make your site faster than light in <1 minute; instant page loads in 723 bytes.",
"version": "2.0.1",
"description": "Make your site faster than light in <1 minute; instant page loads in 738 bytes.",
"main": "tachyon.js",
"scripts": {
"minify": "uglifyjs -c -m --module --verbose tachyon.js > tachyon.min.js",
"test": "http-server test/ && rm test/tachyon.js"
"test": "cp tachyon.js test/ && http-server test/ && rm test/tachyon.js"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion tachyon/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Tachyon
## Make your site faster than light in <1 minute; instant page loads in 723 bytes.
## Make your site faster than light in <1 minute; instant page loads in 738 bytes.

**For documentation related to Tachyon, please reference the [website](https://fasterthanlight.net/) and [github repository](https://github.com/weebney/tachyon).**
12 changes: 7 additions & 5 deletions tachyon/tachyon.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tachyon.js 2.0.0 - @weebney - MIT License
// tachyon.js 2.0.1 - @weebney - MIT License
const bodyDataValues = document.body.dataset;
const whitelistEnabled = 'tachyonWhitelist' in bodyDataValues;
const sameOriginOnly = 'tachyonSameOrigin' in bodyDataValues;
Expand All @@ -25,10 +25,12 @@ function toggleLinkTag() {
}

function initializeListeners(node) {
const listed = 'tachyon' in node.dataset;
if ((node.tagName === 'A' && node.href) && (listed === whitelistEnabled || sameOriginOnly)
&& (!sameOriginOnly || (listed || (node.origin === window.location.origin)))) {
['mouseover', 'mouseout', 'touchstart', 'touchend'].forEach((eventName) => node.addEventListener(eventName, toggleLinkTag, { passive: true }));
if (node.dataset) {
const listed = 'tachyon' in node.dataset;
if ((node.tagName === 'A' && node.href) && (listed === whitelistEnabled || sameOriginOnly)
&& (!sameOriginOnly || (listed || (node.origin === window.location.origin)))) {
['mouseover', 'mouseout', 'touchstart', 'touchend'].forEach((eventName) => node.addEventListener(eventName, toggleLinkTag, { passive: true }));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion tachyon/tachyon.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tachyon/wordpress/tachyon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Tachyon
* Plugin URI: https://fasterthanlight.net/
* Description: Make your WordPress site faster than light.
* Version: 2.0.0
* Version: 2.0.1
* Author: weebney
* Author URI: https://github.com/weebney
* License: MIT
Expand Down
Binary file modified tachyon/wordpress/tachyon.zip
Binary file not shown.

0 comments on commit 29a9290

Please sign in to comment.