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

Frontend javascript files are really big #53

Open
jcgueriaud1 opened this issue May 4, 2020 · 14 comments
Open

Frontend javascript files are really big #53

jcgueriaud1 opened this issue May 4, 2020 · 14 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jcgueriaud1
Copy link

Hi,

It's not a bug but if you run a webpack bundle analyzer in a vaadin application, moment js and moment timezone js will take more place than vaadin libraries (all components).

Is it possible to reduce the size of the js libraries?
Especially moment js takes 4Mb. (unpacked) because it's embedding all the locales.
fullcalendar-core takes 1.8Mb (compared to moment-js it's not that big)

Perhaps luxon could help: https://www.npmjs.com/package/luxon , https://fullcalendar.io/docs/luxon-plugin

@stefanuebe
Copy link
Owner

Hi, I'll have a look on that in the near future. Unfortunately I also think that having all the locales should not be the basic setup, it was in fact the fastest possible solution doable by me fixing another bug regarding localization.

I'll try to find a different approach, where only needed locales will be imported.

@stefanuebe stefanuebe added the enhancement New feature or request label May 11, 2020
@stefanuebe
Copy link
Owner

stefanuebe commented May 14, 2020

Ok, after rereading this issue with a clearer head (don't ask for details, typical parental things :D), I get what you want.

Thought this is related to locale-all.js but now I realize it's related to moment vs luxon.

Since I personally never used the webpack bundle analyzer before, can you give me a short example of how you used it, so that I can simply re-run your analysis? Would help me to see, if it makes a difference if I implement Luxon instead of moment / moment-timezone (which takes only some KB of space on the disk, so this 4 MB confuse me).

@stefanuebe stefanuebe added the help wanted Extra attention is needed label May 14, 2020
@jcgueriaud1
Copy link
Author

Yes of course.

It takes 3 steps in a V14+ npm project:

  1. install an npm dependency: npm install --save-dev webpack-bundle-analyzer
  2. modify webpack.config.json:
    const merge = require('webpack-merge');
    const flowDefaults = require('./webpack.generated.js');
    const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
    module.exports = merge(flowDefaults, {
    plugins: [
    new BundleAnalyzerPlugin({
    analyzerMode: 'static',
    openAnalyzer: true
    })
    ]
    });
  3. build frontend (either in the dev mode with e.g. mvn jetty:run or in the prod mode with npm package -Pproduction). The bundle size report will open automatically.

(These steps come from Viktor :) )

@fschon
Copy link

fschon commented May 25, 2020

Hi Stefan,

If it helps, here is a screenshot of my webpack bundle analysis:

image

@stefanuebe
Copy link
Owner

I'll try to get rid of the moment lib.

Can you test in meanwhile please how it looks like with 14.2.? In my case the libs (in dev mode) are just some hundreds of KB, not 4 MB (anymore?).

@fschon
Copy link

fschon commented May 28, 2020

Hi Stefan. Thx for the support. My above webpack bundle analysis screenshot was with 14.2 production mode.

@stefanuebe
Copy link
Owner

Can you please re-check with the latest version? Should not be using moment.js at all anymore.

@fschon
Copy link

fschon commented Jun 2, 2020

Hi Stefan,

Looks great thanks. No sign of moment.js.

I have also moved from 14.2 to 16.rc2 so the bundle analysis looks different.

image

@jcgueriaud1
Copy link
Author

The bundle size has been reduced from 2.56MiB to 1.86MiB.

Thanks a lot Stefan!

@stefanuebe
Copy link
Owner

Guys, sorry, but it looks like I have to reintroduce the moment js for now. The behavior of times regarding timezones is now very buggy and I do not have the time to dig deeper into it. So easiest for now is to reuse it. I hope, that with 14.2. the 700KB is not too much to stop you from using it :(

@stefanuebe stefanuebe reopened this Jun 2, 2020
@stefanuebe
Copy link
Owner

Reopened for later research

@jcgueriaud1
Copy link
Author

No, it's fine. It's more a nice to have.

One other way could be to cut the vaadin bundle into pieces but there is no way to do that (not yet).

@fschon
Copy link

fschon commented Jul 4, 2020

Hi Stefan. Will you still be getting a chance to work on this issue, or is it on the back burner? Thanks. Franz

@martinisraelsen
Copy link

This may or may not be related:

While looking for something else, I stumbled into this article that describe how size can grow if Moment.js is referenced multiple times. Don't know if this is the case or if it even applies for Vaadin components, but thought I would share.

https://medium.com/collaborne-engineering/polymer-how-we-wasted-1-5-mb-by-importing-external-libraries-wrongly-we-vulcanize-our-polyme-3534ae614454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants