vaadin-fullcalendar icon indicating copy to clipboard operation
vaadin-fullcalendar copied to clipboard

Frontend javascript files are really big

Open jcgueriaud1 opened this issue 4 years ago • 14 comments

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

jcgueriaud1 avatar May 04 '20 15:05 jcgueriaud1

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 avatar May 06 '20 11:05 stefanuebe

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 avatar May 14 '20 08:05 stefanuebe

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 :) )

jcgueriaud1 avatar May 14 '20 08:05 jcgueriaud1

Hi Stefan,

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

image

fschon avatar May 25 '20 13:05 fschon

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?).

stefanuebe avatar May 28 '20 07:05 stefanuebe

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

fschon avatar May 28 '20 08:05 fschon

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

stefanuebe avatar Jun 02 '20 09:06 stefanuebe

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

fschon avatar Jun 02 '20 12:06 fschon

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

Thanks a lot Stefan!

jcgueriaud1 avatar Jun 02 '20 12:06 jcgueriaud1

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 avatar Jun 02 '20 14:06 stefanuebe

Reopened for later research

stefanuebe avatar Jun 02 '20 14:06 stefanuebe

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).

jcgueriaud1 avatar Jun 02 '20 14:06 jcgueriaud1

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

fschon avatar Jul 04 '20 13:07 fschon

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

martinisraelsen avatar Oct 06 '20 13:10 martinisraelsen