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.

General information

  • SDK version: 3.x
  • Environment: both
  • Browser and OS all

Issue description

The generated dist/index.js is pretty big and drastically increases the size of release bundles. This is especially painful when the only thing being used is client and hostedFields, which is a pretty common scenario. let {client, hostedFields} = require('braintree-web') is over 500k!

package.json has a browser field that redirects webpack includes to the dist folder, which also has built versions of client and hostedFields that are much larger than they need to be due to polyfills etc…

In many builds these are redundant and prevent effective tree-shaking, or reuse of existing polyfill libs.

The workaround for this is to require('braintree-web/client/index.js') directly, this prevents the ‘browser’ redirect in package.json from taking effect. By doing this, it’s possible to reduce the size of the included script massively. Webpack analyzer shows my size decreased to 50k, gzipped 14.5k. There’s probably room to decrease this even more, since a lot of the deps appear to be coming from /lib, which looks like some materialized versions of some libs that (may?) be npm installable.

While many users will need to link directly to a /dist script, the ‘browser’ field should probably be removed from package.json. That’s only going to be used by folks who already have a build solution, like webpack or browserify, and for those users it’s better to just allow webpack to follow the requires and do it’s thing.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:7
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
KasperAnderssoncommented, Dec 10, 2021

Hi @crookedneighbor , When is v4 planned? The bundle size still seems to be a issue.

2reactions
719mediacommented, Oct 25, 2019

@claytongulick you can try to do

import braintreeClient from 'braintree-web/client';
import braintreeHostedFields from 'braintree-web/hosted-fields';

to get what you want

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spec Screenplay Page Properties and Script Length
The average feature screenplay, traditionally, is between 95 and 125 pages long. In Hollywood these days scripts generally don't run longer than 114...
Read more >
font-size - CSS: Cascading Style Sheets - MDN Web Docs
The font-size CSS property sets the size of the font. Changing the font size also updates the sizes of the font size-relative units, ......
Read more >
CSS Font Size - W3Schools
Note: If you do not specify a font size, the default size for normal text, like paragraphs, is 16px (16px=1em). Set Font Size...
Read more >
Font sizes, families, and styles - Overleaf, Online LaTeX Editor
Introduction. LaTeX normally chooses the appropriate font and font size based on the logical structure of the document (e.g. sections).
Read more >
Changing the font size in LaTeX - texblog
Changing the font size on a document-wide level. The standard classes, article, report and book support 3 different font sizes, 10pt, 11pt, 12pt...
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