instascan icon indicating copy to clipboard operation
instascan copied to clipboard

bundle size? can it be made smaller?

Open NullVoxPopuli opened this issue 6 years ago • 5 comments

I'm analyzing my own app looking for things to slim down, and noticed that instascan takes up the most space? (even in development mode!) image

those sizes are all the gzipped sizes. instascan's index.js is 2.19MB. I'm guessing most of that is zxing.js ?

Is there anything that can be done?

The QRCode package is quite small: image but I know it wouldn't have any image-processing utilities, which I'm sure is the bulk of what zxing.js is doing.

NullVoxPopuli avatar Jun 21 '18 09:06 NullVoxPopuli

maybe using jsqr https://github.com/cozmo/jsQR instead of zxing would help? jsqr is 44.8 KB https://bundlephobia.com/[email protected] though, this zxing is https://www.npmjs.com/package/@jakedchampion/zxing is 12.1 KB... so I wonder were the bulk of the 380 KB is coming from. :-\

NullVoxPopuli avatar Jun 21 '18 10:06 NullVoxPopuli

maybe it's these things:

// https://bundlephobia.com/[email protected] 28.4KB
require('babel-polyfill');
// https://bundlephobia.com/[email protected] 19.1KB
require('webrtc-adapter');

are those needed? I also wonder if I'm not minifying as well as bundlephobia is... gonna look into that. update: my minifying is fine, so I guess I'm just not accounting for a bunch of tiny deps in instascan?

update2: 30.5KB: https://bundlephobia.com/[email protected] 19.1KB https://bundlephobia.com/[email protected] 28.4KB https://bundlephobia.com/[email protected]

  • 12.1 KB if using jakedchampion/zxing

So.. I'm still missing a couple hundred KB :-\ hmm

the biggest one is fsm-as-promised -- is that needed?

NullVoxPopuli avatar Jun 21 '18 10:06 NullVoxPopuli

I think dropping babel-polyfill is a good idea anyways; it shouldn't be shipped with a module. I'm getting runtime errors because I need to have it loaded on the page before I import instascan, but if I do that, it throws an error about only one instance being allowed when I do finally import instascan.

ArcanoxDragon avatar Aug 14 '18 18:08 ArcanoxDragon

The problem is actual.

Without import instascan (Parsed size 500 KB)

2018-12-27 13-52-53

With import instascan (Parsed size 2.22 MB)

2018-12-27 13-51-49

Total Parsed size ~1720 KB

sinitsyn-alex avatar Dec 27 '18 09:12 sinitsyn-alex

@sinitsyn-alex I changed to "qr-scanner": "github:nimiq/qr-scanner",

it's a smidge slower, but is much smaller

NullVoxPopuli avatar Mar 06 '19 01:03 NullVoxPopuli