question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reduce the size of jsdom (and its dependencies)

See original GitHub issue

I occasionally see the size of jsdom cited as a reason to avoid it and prefer lighter packages instead. While an extensive implementation of the web standards will never be tiny, I believe that the total installation size of jsdom (13 MB / 21,9 MB) could be cut in half by merely reducing bloat.

The sizes shown within parentheses are with and without disk compression, and accounting for the removal of subdependencies. These are the three most important changes we could make to reduce our installed size:

request/request-promise-core - (5,4 MB / 10,6 MB)

The big one. request includes many large dependencies which we have no need for. request-promise-core contributes a significant chunk on its own, since it depends on the whole lodash package (1,4 MB / 5,1 MB) and has yet to merge https://github.com/request/promise-core/pull/7.

Replacing these with either a lighter alternative dependency or a proper implementation of the Fetch Standard would be a large win.

acorn/acorn-globals/escodegen - (2,7 MB / 3 MB)

The acorn, acorn-globals and escodegen dependencies are only used when jsdom is browserified. While we should continue to support browserification, it is an uncommon way to use jsdom.

I believe it makes sense to make these dependencies optional the same way the canvas-related dependencies are.

jsdom/living/generated/ - (1,2 MB / 1,5 MB)

With all the dependencies above removed, the largest contributor to size is actually jsdom’s generated directory. While we obviously need this code in some form, there seems to be a lot of room for deduplication between these files.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
domeniccommented, Oct 18, 2018

Replacing these with either a lighter alternative dependency or a proper implementation of the Fetch Standard would be a large win.

For sure. Just a lot of work 😃.

I believe it makes sense to make these dependencies optional the same way the canvas-related dependencies are.

I would rather find a way to use the browser package.json field so that these don’t get loaded at runtime for Node consumers. I think I’m OK with Node consumers downloading extra packages, in order to give browser consumers a better out of the box experience, as long as it doesn’t impact startup time.

there seems to be a lot of room for deduplication between these files.

I’d be curious to see what concrete proposals there are, but in theory this seems doable. I’m not sure we’d want to e.g. minify the output though…

Read more comments on GitHub >

github_iconTop Results From Across the Web

jsdom - npm
jsdom. jsdom is a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards, for use with Node.js.
Read more >
jsdom dependency needed? - Google Groups
Hi,. I installed blockly through npm (using the git repository). I noticed that my vendor packages grew quite a bit in size and...
Read more >
Set size of window in Jest and jest-dom and jsdom
The 768 and 1024 is a default, Jest is configuring jsdom for your test with. You can overwrite window.innerHeight in your test.
Read more >
Testing with Node, Jest, and JSDOM - Manning Publications
Through the window object, you can change a page's content, ... In main.js , find the button by its ID and attach a...
Read more >
Web scraping for web developers: a concise summary
It requires a negligible amount of computing power and the least time ... Generally, it's a lower level API than Puppeteer, so you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found