Skip to content

Some optimizations by hand, add TypeScript declaration#35

Open
jhpratt wants to merge 1 commit intotypicode:masterfrom
jhpratt:master
Open

Some optimizations by hand, add TypeScript declaration#35
jhpratt wants to merge 1 commit intotypicode:masterfrom
jhpratt:master

Conversation

@jhpratt
Copy link

@jhpratt jhpratt commented Dec 6, 2018

Basically, I added a TS declaration and reduced the minzip size from 629B to 582B (-7.5%) and the min-brotli size from 524B to 487B (-7.1%). I intentionally did not modernize any code, so as to preserve browser compatibility.

I also updated dependencies (for security reasons) and replace uglify-js with terser.


Optimizations explanation:

Line 1: See line 95.

Line 17: If json is not present, it's the fallback anyways. We can
safely remove this value from the checks. Though replacing the indexOf
check with multiple checks seems like it would increase size, gzip
easily turns this into a net savings.

Line 95: If window is defined, we'd be using the window variable
anyways. If it wasn't defined (AKA held the value undefined), we would
use undefined. This can be simplified into just using window.
Because we're simply passing the verbatim into the IIFE, we can
eliminate this entirely.

Resolves #29.

Also update dependencies (for security reasons) and replace uglify-js
with terser.

I intentionally did not modernize any code, so as to preserve browser
compatibility.

---

Optimizations explanation:

Line 1: See line 95.

Line 17: If `json` is not present, it's the fallback anyways. We can
safely remove this value from the checks. Though replacing the `indexOf`
check with multiple checks seems like it would increase size, gzip
easily turns this into a net savings.

Line 95: If window is defined, we'd be using the window variable
anyways. If it wasn't defined (AKA held the value `undefined`), we would
use `undefined`. This can be simplified into just using `window`.
Because we're simply passing the verbatim into the IIFE, we can
eliminate this entirely.
@jhpratt
Copy link
Author

jhpratt commented Dec 6, 2018

Looks like the test is failing due to the environment that Travis is configured for, not because of an issue with the library.

@jhpratt
Copy link
Author

jhpratt commented Dec 9, 2018

Just in case anyone runs across this, I've just published esfetch, which is a drop-in replacement for fetchival. I modernized the code (it can be transpiled down, of course), and shaved about another 10% off the compressed size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant