Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce size (83kb min not gz is too big) #73

Closed
tracker1 opened this issue Mar 9, 2019 · 11 comments
Closed

Reduce size (83kb min not gz is too big) #73

tracker1 opened this issue Mar 9, 2019 · 11 comments

Comments

@tracker1
Copy link

tracker1 commented Mar 9, 2019

  • Consider Rollup over webpack
  • is Babel really needed?
  • with webpack + babel, specify a minimum browser version (IE11) for preset-env
  • run the output through closure compiler to further reduce the size
@philwolstenholme
Copy link

An option to exclude the Array.from() polyfill (polyfills/array.from.js) could reduce the size a bit too, for users who are already loading a polyfill for this feature, or for users who only support browsers with native support for Array.from()

I think I've seen other libraries do this by providing a library.min.js file without the extras, and a library.all.min.js with the extras bundled in.

@koddr
Copy link
Owner

koddr commented Mar 17, 2019

@tracker1 @philwolstenholme fix 6.0.0, thanks for support!

@koddr koddr closed this as completed Mar 17, 2019
@tracker1
Copy link
Author

@koddr would still add closure[1], to see how small you can get it, 38kb is still very large for what this library does. Another possibility would be conditional builds, so only the social networks desired are actually built. Like one with top (facebook, twitter, instagram, pinterest), and another with all.

Alternatively a plugin structure, so that each social network is a separate add-in that can be joined into a single script after the fact, or loaded adjacently.

[1] https://github.com/ampproject/rollup-plugin-closure-compiler

@koddr
Copy link
Owner

koddr commented Mar 18, 2019

@tracker1 hm.. rollup-plugin-closure-compiler does similar 38kb.. what's principle different between him and rollup-plugin-uglify (what I use in 6.0.0)?

@koddr koddr reopened this Mar 18, 2019
@tracker1
Copy link
Author

If you can use the ADVANCED option for closure, it should gain you some size...

@koddr
Copy link
Owner

koddr commented Mar 18, 2019

And one more.. how do you want to cut Babel from build? I use class and other ES6+ code, I have no idea how I may cut this JS compiler. Can you help me?

@koddr
Copy link
Owner

koddr commented Mar 18, 2019

@tracker1

If you can use the ADVANCED option for closure, it should gain you some size...

So, I use it:

...
compiler({
  compilation_level: "ADVANCED"
})
...

Output size is 34 857 bytes (~35 kb). Profit is ~3 kb. Okay.

@tracker1
Copy link
Author

class syntax would be hard without babel... you'd have to convert everything to prototype based inheritance modelling, which may not be worth it... though you may gain more by setting the minimum browser for your @babel/preset-env to IE9 or IE11 (depending on where you want to cut) as it is, it's generating transforms and using fills you don't actually need.

@tracker1
Copy link
Author

tracker1 commented Mar 18, 2019

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
           "ie": 9,
          "esmodules": true
        },
        "useBuiltIns": "usage",
        "loose": true
      }
    ]
  ]
}

@tracker1
Copy link
Author

You shouldn't need the separate Array.from polyfill, the above should give it to you as-needed.

@koddr
Copy link
Owner

koddr commented Mar 18, 2019

@tracker1 I switched back compilation_level to "SIMPLE" and delete "loose": true, because it's totally broke my bundle. You may see errors at 6.0.3 version.

Now, goodshare.js is back to 38 Kb and... it's better, than not working bundle!

@koddr koddr closed this as completed Mar 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants