fetchival icon indicating copy to clipboard operation
fetchival copied to clipboard

Some optimizations by hand, add TypeScript declaration

Open jhpratt opened this issue 6 years ago • 2 comments

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.

jhpratt avatar Dec 06 '18 06:12 jhpratt

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

jhpratt avatar Dec 06 '18 06:12 jhpratt

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.

jhpratt avatar Dec 09 '18 00:12 jhpratt